Function: choose-completion

choose-completion is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(choose-completion &optional EVENT NO-EXIT NO-QUIT)

Documentation

Choose the completion at point.

If EVENT, use EVENT's position to determine the starting position. With prefix argument NO-EXIT, insert the completion at point to the minibuffer, but don't exit the minibuffer. When the prefix argument is not provided, then whether to exit the minibuffer depends on the value of completion-no-auto-exit. If NO-QUIT is non-nil, insert the completion at point to the minibuffer, but don't quit the completions window.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun choose-completion (&optional event no-exit no-quit)
  "Choose the completion at point.
If EVENT, use EVENT's position to determine the starting position.
With prefix argument NO-EXIT, insert the completion at point to the
minibuffer, but don't exit the minibuffer.  When the prefix argument
is not provided, then whether to exit the minibuffer depends on the value
of `completion-no-auto-exit'.
If NO-QUIT is non-nil, insert the completion at point to the
minibuffer, but don't quit the completions window."
  (interactive (list last-nonmenu-event current-prefix-arg))
  ;; In case this is run via the mouse, give temporary modes such as
  ;; isearch a chance to turn off.
  (run-hooks 'mouse-leave-buffer-hook)
  (with-current-buffer (window-buffer (posn-window (event-start event)))
    (let ((buffer completion-reference-buffer)
          (base-position completion-base-position)
          (insert-function completion-list-insert-choice-function)
          (completion-no-auto-exit (if no-exit t completion-no-auto-exit))
          (choice
           (if choose-completion-deselect-if-after
               (or (get-text-property (posn-point (event-start event))
                                      'completion--string)
                   (error "No completion here"))
           (save-excursion
             (goto-char (posn-point (event-start event)))
             (let (beg)
               (cond
                ((and (not (eobp))
                      (get-text-property (point) 'completion--string))
                 (setq beg (1+ (point))))
                ((and (not (bobp))
                      (get-text-property (1- (point)) 'completion--string))
                 (setq beg (point)))
                (t (error "No completion here")))
               (setq beg (or (previous-single-property-change
                              beg 'completion--string)
                             beg))
               (get-text-property beg 'completion--string))))))

      (unless (buffer-live-p buffer)
        (error "Destination buffer is dead"))
      (unless no-quit
        (quit-window nil (posn-window (event-start event))))

      (with-current-buffer buffer
        (choose-completion-string
         choice buffer
         (or base-position
             ;; If all else fails, just guess.
             (list (choose-completion-guess-base-position choice)))
         insert-function)))))