(cat (if completion-category (format " %s" completion-category) "")))
(with-current-buffer standard-output
(goto-char (point-max))
- (if completions-header-format
- (let ((heading
- (format-spec completions-header-format
- (list (cons ?s (length completions))
- (cons ?t sort-desc)
- (cons ?r pred-desc)
- (cons ?c cat)))))
- (add-face-text-property
- 0 (length heading) 'completions-heading t heading)
- (insert heading))
- (unless completion-show-help
- ;; Ensure beginning-of-buffer isn't a completion.
- (insert (propertize "\n" 'face '(:height 0)))))
+ (when completions-header-format
+ (let ((heading
+ (format-spec completions-header-format
+ (list (cons ?s (length completions))
+ (cons ?t sort-desc)
+ (cons ?r pred-desc)
+ (cons ?c cat)))))
+ (add-face-text-property
+ 0 (length heading) 'completions-heading t heading)
+ (insert heading)))
(completion--insert-strings completions group-fun)))
(run-hooks 'completion-setup-hook)
(resize-temp-buffer-window win))
(fit-window-to-buffer win completions-max-height)))
-(defcustom completion-auto-deselect t
- "If non-nil, deselect current completion candidate when you type in minibuffer.
-
-A non-nil value means that after typing at the minibuffer prompt,
-any completion candidate highlighted in *Completions* window (to
-indicate that it is the selected candidate) will be un-highlighted,
-and point in the *Completions* window will be moved off such a candidate.
-This means that `RET' (`minibuffer-choose-completion-or-exit') will exit
-the minubuffer with the minibuffer's current contents, instead of the
-selected completion candidate."
- :type '(choice (const :tag "Candidates in *Completions* stay selected as you type" nil)
- (const :tag "Typing deselects any completion candidate in *Completions*" t))
- :version "30.1")
-
-(defun completions--deselect ()
- "If point is in a completion candidate, move to just after the end of it.
-
-The candidate will still be chosen by `choose-completion' unless
-`choose-completion-deselect-if-after' is non-nil."
- (when (get-text-property (point) 'completion--string)
- (goto-char (or (next-single-property-change (point) 'completion--string)
- (point-max)))))
-
-(defun completions--after-change (_start _end _old-len)
- "Update displayed *Completions* buffer after change in buffer contents."
- (when completion-auto-deselect
- (when-let (window (get-buffer-window "*Completions*" 0))
- (with-selected-window window
- (completions--deselect)))))
-
(defcustom minibuffer-read-sort-order-with-completion nil
"Whether to use completion for reading minibuffer completions sort order.
If this user options is nil (the default),
;; If there are no completions, or if the current input is already
;; the sole completion, then hide (previous&stale) completions.
(minibuffer-hide-completions)
- (remove-hook 'after-change-functions #'completions--after-change t)
(if completions
(completion--message "Sole completion")
(completion--fail)))
(body-function
. ,#'(lambda (_window)
(with-current-buffer mainbuf
- (when completion-auto-deselect
- (add-hook 'after-change-functions #'completions--after-change nil t))
;; Remove the base-size tail because `sort' requires a properly
;; nil-terminated list.
(when last (setcdr last nil))
completion-in-region-mode-predicate)
(setq-local minibuffer-completion-auto-choose nil)
(add-hook 'post-command-hook #'completion-in-region--postch)
- (let* ((keymap completion-in-region-mode-map)
- (keymap (if minibuffer-visible-completions
- (make-composed-keymap
- (list minibuffer-visible-completions-map
- keymap))
- keymap)))
- (push `(completion-in-region-mode . ,keymap)
- minor-mode-overriding-map-alist))))
+ (push `(completion-in-region-mode . ,completion-in-region-mode-map)
+ minor-mode-overriding-map-alist)))
;; Define-minor-mode added our keymap to minor-mode-map-alist, but we want it
;; on minor-mode-overriding-map-alist instead.
:interactive nil
;; Enable text conversion, but always make sure `RET' does
;; something.
- (setq text-conversion-style 'action)
- (when minibuffer-visible-completions
- (setq-local minibuffer-completion-auto-choose nil)))
-
-(defcustom minibuffer-visible-completions nil
- "Whether candidates shown in *Completions* can be navigated from minibuffer.
-When non-nil, if the *Completions* buffer is displayed in a window,
-you can use the arrow keys in the minibuffer to move the cursor in
-the window showing the *Completions* buffer. Typing `RET' selects
-the highlighted completion candidate.
-If the *Completions* buffer is not displayed on the screen, or this
-variable is nil, the arrow keys move point in the minibuffer as usual,
-and `RET' accepts the input typed into the minibuffer."
- :type 'boolean
- :version "30.1")
+ (setq text-conversion-style 'action))
-(defun minibuffer-visible-completions-bind (binding)
- "Use BINDING when completions are visible.
-Return an item that is enabled only when a window
-displaying the *Completions* buffer exists."
- `(menu-item
- "" ,binding
- :filter ,(lambda (cmd)
- (when-let ((window (get-buffer-window "*Completions*" 0)))
- (when (eq (buffer-local-value 'completion-reference-buffer
- (window-buffer window))
- (window-buffer (active-minibuffer-window)))
- cmd)))))
-
-(defvar-keymap minibuffer-visible-completions-map
- :doc "Local keymap for minibuffer input with visible completions."
- "<left>" (minibuffer-visible-completions-bind #'minibuffer-previous-completion)
- "<right>" (minibuffer-visible-completions-bind #'minibuffer-next-completion)
- "<up>" (minibuffer-visible-completions-bind #'minibuffer-previous-line-completion)
- "<down>" (minibuffer-visible-completions-bind #'minibuffer-next-line-completion)
- "RET" (minibuffer-visible-completions-bind #'minibuffer-choose-completion-or-exit)
- "C-g" (minibuffer-visible-completions-bind #'minibuffer-hide-completions))
\f
;;; Completion tables.
;; `read-from-minibuffer' uses 1-based index.
(1+ (cdr initial-input)))))
- (let* ((base-keymap (if require-match
- minibuffer-local-must-match-map
- minibuffer-local-completion-map))
- (keymap (if minibuffer-visible-completions
- (make-composed-keymap
- (list minibuffer-visible-completions-map
- base-keymap))
- base-keymap))
+ (let* ((keymap (if require-match
+ minibuffer-local-must-match-map
+ minibuffer-local-completion-map))
(buffer (current-buffer))
(c-i-c completion-ignore-case)
(result
(next-line-completion (or n 1))
(next-completion (or n 1)))
(when auto-choose
- (let ((completion-use-base-affixes t)
- (completion-auto-deselect nil))
+ (let ((completion-use-base-affixes t))
(choose-completion nil t t))))))
(defun minibuffer-previous-completion (&optional n)
(let ((completion-use-base-affixes t))
(choose-completion nil no-exit no-quit))))
-(defun minibuffer-choose-completion-or-exit (&optional no-exit no-quit)
- "Choose the completion from the minibuffer or exit the minibuffer.
-When `minibuffer-choose-completion' can't find a completion candidate
-in the completions window, then exit the minibuffer using its present
-contents."
- (interactive "P")
- (condition-case nil
- (let ((choose-completion-deselect-if-after t))
- (minibuffer-choose-completion no-exit no-quit))
- (error (minibuffer-complete-and-exit))))
-
(defun minibuffer-complete-history ()
"Complete the minibuffer history as far as possible.
Like `minibuffer-complete' but completes on the history items
(if pos (goto-char pos))))
(setq n (1+ n)))))
-(defvar choose-completion-deselect-if-after nil
- "If non-nil, don't choose a completion candidate if point is right after it.
-
-This makes `completions--deselect' effective.")
-
(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.
(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
- (if-let ((str (get-text-property (posn-point (event-start event)) 'completion--string)))
- (substring-no-properties str)
- (error "No completion here"))
(save-excursion
(goto-char (posn-point (event-start event)))
(let (beg)
beg 'completion--string)
beg))
(substring-no-properties
- (get-text-property beg 'completion--string)))))))
+ (get-text-property beg 'completion--string))))))
(unless (buffer-live-p buffer)
(error "Destination buffer is dead"))
;; Maybe insert help string.
(when completion-show-help
(goto-char (point-min))
- (if minibuffer-visible-completions
- (let ((helps
- (with-current-buffer (window-buffer (active-minibuffer-window))
- (list
- (substitute-command-keys
- (if (display-mouse-p)
- "Click or type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n"
- "Type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n"))
- (substitute-command-keys
- "Type \\[minibuffer-next-completion], \\[minibuffer-previous-completion], \
-\\[minibuffer-next-line-completion], \\[minibuffer-previous-line-completion] \
-to move point between completions.\n\n")))))
- (dolist (help helps)
- (insert help)))
- (insert (substitute-command-keys
- (if (display-mouse-p)
- "Click or type \\[minibuffer-choose-completion] on a completion to select it.\n"
- "Type \\[minibuffer-choose-completion] on a completion to select it.\n")))
- (insert (substitute-command-keys
- "Type \\[minibuffer-next-completion] or \\[minibuffer-previous-completion] \
-to move point between completions.\n\n")))))))
+ (insert (substitute-command-keys
+ (if (display-mouse-p)
+ "Click or type \\[minibuffer-choose-completion] on a completion to select it.\n"
+ "Type \\[minibuffer-choose-completion] on a completion to select it.\n")))
+ (insert (substitute-command-keys
+ "Type \\[minibuffer-next-completion] or \\[minibuffer-previous-completion] \
+to move point between completions.\n\n"))))))
(add-hook 'completion-setup-hook #'completion-setup-function)