aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Aguilar Mena2022-03-13 20:34:19 +0100
committerJimmy Aguilar Mena2022-03-13 20:34:19 +0100
commite303fa3e605bd9d0f43a5acaa39e9a24ac44e1db (patch)
tree4b83b99b244f7c34c4b118f376309e3728a10133
parent10cb469ee81c0ff2ad3740e7099227d0a6907545 (diff)
downloademacs-e303fa3e605bd9d0f43a5acaa39e9a24ac44e1db.tar.gz
emacs-e303fa3e605bd9d0f43a5acaa39e9a24ac44e1db.zip
Use the new cursor-face feature to highlight completions.
* lisp/minibuffer.el (completions-highlight-face) : New custom. (completions-highlight-mode) : Removed
-rw-r--r--doc/emacs/mini.texi10
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/minibuffer.el48
3 files changed, 17 insertions, 48 deletions
diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi
index 718ac3ec7a7..eca0464fdf5 100644
--- a/doc/emacs/mini.texi
+++ b/doc/emacs/mini.texi
@@ -676,10 +676,12 @@ useful ones are @code{face} or @code{cursor-intangible}
676(@pxref{Special Properties,,Properties with Special Meanings, elisp, 676(@pxref{Special Properties,,Properties with Special Meanings, elisp,
677The Emacs Lisp Reference Manual}). 677The Emacs Lisp Reference Manual}).
678 678
679@vindex completions-highlight-mode 679@vindex completions-highlight-face
680When the mode @code{completions-highlight-mode} is active the candidate 680When @code{completions-highlight-face} is a face name; then the
681under the cursor is highlighted when the completion window is 681current completion candidate will be highlighted with that face. The
682selected. The mode uses the face @code{completions-highlight}. 682default value is @code{completions-highlight}. When the value is
683@code{nil} no highlight is performed. This feature sets the text
684property @code{cursor-face}.
683 685
684@node Minibuffer History 686@node Minibuffer History
685@section Minibuffer History 687@section Minibuffer History
diff --git a/etc/NEWS b/etc/NEWS
index 76da1787a24..69c3e16b560 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -574,9 +574,10 @@ It may contain a %s to show the total number of completions. If nil no
574completions are shown. 574completions are shown.
575 575
576+++ 576+++
577*** New mode 'completions-highlight-mode'. 577*** New option 'completions-highlight-face'.
578This mode highlights the current candidate in the *Completions* buffer 578When this variable is a face name it highlights the current candidate
579with the 'completions-highlight' face. 579in the *Completions* buffer with that face. When the value is nil no
580highlight is performed at all.
580 581
581 582
582** Isearch and Replace 583** Isearch and Replace
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 0cab09bd982..878a1104ebe 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2035,7 +2035,7 @@ Runs of equal candidate strings are eliminated. GROUP-FUN is a
2035 (funcall group-fun str 'transform) 2035 (funcall group-fun str 'transform)
2036 str)) 2036 str))
2037 (point)) 2037 (point))
2038 `(mouse-face highlight completion--string ,str)) 2038 `(mouse-face highlight cursor-face ,completions-highlight-face completion--string ,str))
2039 ;; If `str' is a list that has 2 elements, 2039 ;; If `str' is a list that has 2 elements,
2040 ;; then the second element is a suffix annotation. 2040 ;; then the second element is a suffix annotation.
2041 ;; If `str' has 3 elements, then the second element 2041 ;; If `str' has 3 elements, then the second element
@@ -2156,49 +2156,15 @@ candidates."
2156 2156
2157 2157
2158(defface completions-highlight 2158(defface completions-highlight
2159 '((t :inherit highlight :extend t)) 2159 '((t :inherit highlight))
2160 "Default face for highlighting the current line in `completions-highlight-mode'." 2160 "Default face for highlighting the current line in `completions-highlight-mode'."
2161 :version "29.1") 2161 :version "29.1")
2162 2162
2163(defvar completions--overlay nil 2163(defcustom completions-highlight-face 'completions-highlight
2164 "Overlay to use when `completions-highlight-mode' is enabled.") 2164 "A face name to highlight current completion candidate.
2165 2165If the value is nil no highlight is performed."
2166(defun completions-highlight--delete () 2166 :type '(choice (const nil) face)
2167 "Highlight current candidate in *Completions* with `completions-highlight'." 2167 :version "29.1")
2168 (when (overlayp completions--overlay)
2169 (delete-overlay completions--overlay)))
2170
2171(defun completions-highlight--highlight ()
2172 "Highlight current candidate if point in a candidate."
2173 (let* ((point (point))
2174 (hpoint (or (and (get-text-property point 'mouse-face) point)
2175 (and (> point 1) (get-text-property (1- point) 'mouse-face) (1- point)))))
2176 (when hpoint
2177 (move-overlay completions--overlay
2178 (previous-single-property-change (1+ hpoint) 'mouse-face nil (point-min))
2179 (next-single-property-change hpoint 'mouse-face nil (point-max))))))
2180
2181(defun completions-highlight--setup-hook ()
2182 "Function to call when enabling the `completion-highlight-mode' mode.
2183It is called when showing the *Completions* buffer."
2184 (with-current-buffer "*Completions*"
2185 (completions-highlight--highlight)
2186 (add-hook 'pre-command-hook #'completions-highlight--delete nil t)
2187 (add-hook 'post-command-hook #'completions-highlight--highlight nil t)))
2188
2189;;;###autoload
2190(define-minor-mode completions-highlight-mode
2191 "Completion highlight mode to enable candidates highlight in the minibuffer."
2192 :global t
2193 :group 'minibuffer
2194 (cond
2195 (completions-highlight-mode
2196 (setq completions--overlay (make-overlay 0 0))
2197 (overlay-put completions--overlay 'face 'completions-highlight)
2198 (add-hook 'completion-setup-hook #'completions-highlight--setup-hook t))
2199 (t
2200 (remove-hook 'completion-setup-hook #'completions-highlight--setup-hook)))
2201 (completions-highlight--delete))
2202 2168
2203(defvar completion-extra-properties nil 2169(defvar completion-extra-properties nil
2204 "Property list of extra properties of the current completion job. 2170 "Property list of extra properties of the current completion job.