From 15e9910aa31b7840e289b753ca5e086ea7238aa5 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 25 Jan 2024 07:54:03 +0100 Subject: [PATCH] =?utf8?q?Highlight=20previously=20used=20completions=20(?= =?utf8?q?=C3=A0=20la=20visited=20links)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * lisp/minibuffer.el (completions-previous-input): New face. (completions-highlight-previous-inputs): New user option. (minibuffer-completion-help): Highlight completion candidates that occur in the minibuffer history, optionally. * doc/emacs/mini.texi (Completion Options): Document new feature. * etc/NEWS: Announce it. --- doc/emacs/mini.texi | 9 +++++++++ etc/NEWS | 7 +++++++ lisp/minibuffer.el | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index e8a35bee791..ad130223e63 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi @@ -1087,6 +1087,15 @@ completion, the annotations show major mode and either the name of file that the buffer is visiting or the name and status of the buffer's process. +@cindex previous input highlighting, in completions +@vindex completions-highlight-previous-inputs +In the @file{*Completions*} buffer, Emacs highlights completion +candidates that appear in the minibuffer history (meaning you have +used them before, @pxref{Minibuffer History}) with face +@code{completions-previous-input}. To disable previous input +highlighting in the @file{*Completions*} buffer, customize +@code{completions-highlight-previous-inputs} to @code{nil}. + @node Minibuffer History @section Minibuffer History @cindex minibuffer history diff --git a/etc/NEWS b/etc/NEWS index 7c175cd876b..d49545c9e28 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -854,6 +854,13 @@ which you can use to customize completion behavior via and you can now customize the face 'completions-heading' to control its appearance. ++++ +*** Highlight previous minibuffer inputs in the completions list +Emacs now highlights completion candidates that appear in the +minibuffer history with face 'completions-previous-input' in the +"*Completions*" buffer. You can disable this highlighting by +customizing 'completions-highlight-previous-inputs' to nil. + ** Pcomplete --- diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 9f3c74b8efb..fe8205a940e 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2615,6 +2615,14 @@ when you select this sort order." (defface completions-heading '((t :inherit shadow)) "Face for the completions headling line.") +(defface completions-previous-input '((t :underline "violet")) + "Face for highlighting previous inputs in the *Completions* buffer.") + +(defcustom completions-highlight-previous-inputs t + "Whether to highlight previously used inputs in the *Completions* buffer." + :version "30.1" + :type 'boolean) + (defun display-completion-list (completions &optional common-substring group-fun) "Display the list of completions, COMPLETIONS, using `standard-output'. Each element may be just a symbol or string @@ -3000,6 +3008,24 @@ completions list." ;; nil-terminated list. (when last (setcdr last nil)) + ;; Highilight previously used completions. + (when-let + ((hist (and completions-highlight-previous-inputs + (not (eq minibuffer-history-variable t)) + (symbol-value minibuffer-history-variable)))) + (setq completions + (mapcar + (lambda (comp) + (if (member (concat minibuffer-completion-base comp) hist) + ;; Avoid modifying the original string. + (let ((copy (copy-sequence comp))) + (font-lock-append-text-property + 0 (length copy) + 'face 'completions-previous-input copy) + copy) + comp)) + completions))) + ;; Sort first using the `display-sort-function'. ;; FIXME: This function is for the output of ;; all-completions, not -- 2.39.5