]> git.eshelyaron.com Git - emacs.git/commitdiff
Highlight previously used completions (à la visited links)
authorEshel Yaron <me@eshelyaron.com>
Thu, 25 Jan 2024 06:54:03 +0000 (07:54 +0100)
committerEshel Yaron <me@eshelyaron.com>
Thu, 25 Jan 2024 07:28:52 +0000 (08:28 +0100)
* 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
etc/NEWS
lisp/minibuffer.el

index e8a35bee7913457d5d89c6fc8b6e88798b23d30e..ad130223e6383b16c2afdb805eb84edc9dade296 100644 (file)
@@ -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
index 7c175cd876ba857680cba12df3f97f83b4a6cca2..d49545c9e280d70f3ad011985fddd2d672cd4461 100644 (file)
--- 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
 
 ---
index 9f3c74b8efb328f3a458eb3be09fd1ca3b82d9b5..fe8205a940e192aa16d6530c9ea65d0373cfe5dd 100644 (file)
@@ -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