aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
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 /lisp
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
Diffstat (limited to 'lisp')
-rw-r--r--lisp/minibuffer.el48
1 files changed, 7 insertions, 41 deletions
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.