diff options
| author | Jimmy Aguilar Mena | 2022-03-13 20:34:19 +0100 |
|---|---|---|
| committer | Jimmy Aguilar Mena | 2022-03-13 20:34:19 +0100 |
| commit | e303fa3e605bd9d0f43a5acaa39e9a24ac44e1db (patch) | |
| tree | 4b83b99b244f7c34c4b118f376309e3728a10133 | |
| parent | 10cb469ee81c0ff2ad3740e7099227d0a6907545 (diff) | |
| download | emacs-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.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 48 |
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, |
| 677 | The Emacs Lisp Reference Manual}). | 677 | The Emacs Lisp Reference Manual}). |
| 678 | 678 | ||
| 679 | @vindex completions-highlight-mode | 679 | @vindex completions-highlight-face |
| 680 | When the mode @code{completions-highlight-mode} is active the candidate | 680 | When @code{completions-highlight-face} is a face name; then the |
| 681 | under the cursor is highlighted when the completion window is | 681 | current completion candidate will be highlighted with that face. The |
| 682 | selected. The mode uses the face @code{completions-highlight}. | 682 | default value is @code{completions-highlight}. When the value is |
| 683 | @code{nil} no highlight is performed. This feature sets the text | ||
| 684 | property @code{cursor-face}. | ||
| 683 | 685 | ||
| 684 | @node Minibuffer History | 686 | @node Minibuffer History |
| 685 | @section Minibuffer History | 687 | @section Minibuffer History |
| @@ -574,9 +574,10 @@ It may contain a %s to show the total number of completions. If nil no | |||
| 574 | completions are shown. | 574 | completions are shown. |
| 575 | 575 | ||
| 576 | +++ | 576 | +++ |
| 577 | *** New mode 'completions-highlight-mode'. | 577 | *** New option 'completions-highlight-face'. |
| 578 | This mode highlights the current candidate in the *Completions* buffer | 578 | When this variable is a face name it highlights the current candidate |
| 579 | with the 'completions-highlight' face. | 579 | in the *Completions* buffer with that face. When the value is nil no |
| 580 | highlight 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 | 2165 | If 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. | ||
| 2183 | It 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. |