(defface completions-previous-input '((t :underline "violet"))
"Face for highlighting previous inputs in the *Completions* buffer.")
+(defface completions-used-input '((t :inherit link-visited))
+ "Face for highlighting used inputs in the *Completions* buffer.")
+
(defcustom completions-highlight-previous-inputs t
"Whether to highlight previously used inputs in the *Completions* buffer."
:version "30.1"
"M-RET" #'minibuffer-choose-completion
"C-x C-v" #'minibuffer-sort-completions
"C-x n" 'minibuffer-narrow-completions-map
- "C-x /" #'minibuffer-set-completion-styles)
+ "C-x /" #'minibuffer-set-completion-styles
+ "C-j" #'minibuffer-apply)
(defvar-keymap minibuffer-local-must-match-map
:doc "Local keymap for minibuffer input with completion, for exact match."
:parent minibuffer-local-completion-map
- "RET" #'minibuffer-complete-and-exit
- "C-j" #'minibuffer-complete-and-exit)
+ "RET" #'minibuffer-complete-and-exit)
(defvar-keymap minibuffer-local-filename-completion-map
:doc "This variable is obsolete and no longer used.")
(define-obsolete-function-alias 'internal-complete-buffer
'completion-buffer-name-table "30.1")
+(defvar-local minibuffer-completion-action nil
+ "Function that `minibuffer-apply' applies to the current input, or nil.")
+
+(defvar-local minibuffer-completion-command nil
+ "The command currently reading input from the minibuffer.")
+
+(defun minibuffer-current-input ()
+ (let* ((beg-end (minibuffer--completion-boundaries))
+ (beg (car beg-end)) (end (cdr beg-end))
+ (str (buffer-substring beg end))
+ (prf (buffer-substring (minibuffer-prompt-end) beg)))
+ (when-let ((adjust-fn (alist-get 'adjust-base-function
+ (completion-metadata
+ (concat prf str)
+ minibuffer-completion-table
+ minibuffer-completion-predicate))))
+ (setq prf (funcall adjust-fn prf)))
+ (cons str prf)))
+
+(defun minibuffer-completion-action ()
+ "Return the completion action function for the current minibuffer."
+ (or minibuffer-completion-action
+ (and (symbolp minibuffer-completion-command)
+ (get minibuffer-completion-command
+ 'minibuffer-action)
+ minibuffer-completion-command)
+ (error "No applicable action")))
+
+(defun minibuffer-apply (action input &optional prefix)
+ "Apply ACTION to current minibuffer INPUT prefixed by PREFIX."
+ (interactive (let* ((input-prefix (minibuffer-current-input))
+ (input (car input-prefix))
+ (prefix (cdr input-prefix)))
+ (list (minibuffer-completion-action) input prefix)))
+ (funcall action (concat prefix input))
+ (when-let ((buf (get-buffer "*Completions*"))
+ (win (get-buffer-window buf 0)))
+ (with-current-buffer buf
+ (save-excursion
+ (goto-char (point-min))
+ (when-let ((pm (text-property-search-forward
+ 'completion--string input t)))
+ (goto-char (prop-match-beginning pm))
+ (setq pm (text-property-search-forward 'cursor-face))
+ (let ((inhibit-read-only t))
+ (add-face-text-property (prop-match-beginning pm) (point)
+ 'completions-used-input)))))))
+
;;; Old-style completion, used in Emacs-21 and Emacs-22.
(defun completion-emacs21-try-completion (string table pred _point)
(result
(minibuffer-with-setup-hook
(lambda ()
+ (setq-local minibuffer-completion-command
+ (car (last (cons this-command
+ (function-alias-p this-command)))))
(setq-local minibuffer-completion-table collection)
(setq-local minibuffer-completion-predicate predicate)
;; FIXME: Remove/rename this var, see the next one.