From e303fa3e605bd9d0f43a5acaa39e9a24ac44e1db Mon Sep 17 00:00:00 2001 From: Jimmy Aguilar Mena Date: Sun, 13 Mar 2022 20:34:19 +0100 Subject: [PATCH] Use the new cursor-face feature to highlight completions. * lisp/minibuffer.el (completions-highlight-face) : New custom. (completions-highlight-mode) : Removed --- doc/emacs/mini.texi | 10 ++++++---- etc/NEWS | 7 ++++--- 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} (@pxref{Special Properties,,Properties with Special Meanings, elisp, The Emacs Lisp Reference Manual}). -@vindex completions-highlight-mode -When the mode @code{completions-highlight-mode} is active the candidate -under the cursor is highlighted when the completion window is -selected. The mode uses the face @code{completions-highlight}. +@vindex completions-highlight-face +When @code{completions-highlight-face} is a face name; then the +current completion candidate will be highlighted with that face. The +default value is @code{completions-highlight}. When the value is +@code{nil} no highlight is performed. This feature sets the text +property @code{cursor-face}. @node Minibuffer History @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 completions are shown. +++ -*** New mode 'completions-highlight-mode'. -This mode highlights the current candidate in the *Completions* buffer -with the 'completions-highlight' face. +*** New option 'completions-highlight-face'. +When this variable is a face name it highlights the current candidate +in the *Completions* buffer with that face. When the value is nil no +highlight is performed at all. ** 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 (funcall group-fun str 'transform) str)) (point)) - `(mouse-face highlight completion--string ,str)) + `(mouse-face highlight cursor-face ,completions-highlight-face completion--string ,str)) ;; If `str' is a list that has 2 elements, ;; then the second element is a suffix annotation. ;; If `str' has 3 elements, then the second element @@ -2156,49 +2156,15 @@ candidates." (defface completions-highlight - '((t :inherit highlight :extend t)) + '((t :inherit highlight)) "Default face for highlighting the current line in `completions-highlight-mode'." :version "29.1") -(defvar completions--overlay nil - "Overlay to use when `completions-highlight-mode' is enabled.") - -(defun completions-highlight--delete () - "Highlight current candidate in *Completions* with `completions-highlight'." - (when (overlayp completions--overlay) - (delete-overlay completions--overlay))) - -(defun completions-highlight--highlight () - "Highlight current candidate if point in a candidate." - (let* ((point (point)) - (hpoint (or (and (get-text-property point 'mouse-face) point) - (and (> point 1) (get-text-property (1- point) 'mouse-face) (1- point))))) - (when hpoint - (move-overlay completions--overlay - (previous-single-property-change (1+ hpoint) 'mouse-face nil (point-min)) - (next-single-property-change hpoint 'mouse-face nil (point-max)))))) - -(defun completions-highlight--setup-hook () - "Function to call when enabling the `completion-highlight-mode' mode. -It is called when showing the *Completions* buffer." - (with-current-buffer "*Completions*" - (completions-highlight--highlight) - (add-hook 'pre-command-hook #'completions-highlight--delete nil t) - (add-hook 'post-command-hook #'completions-highlight--highlight nil t))) - -;;;###autoload -(define-minor-mode completions-highlight-mode - "Completion highlight mode to enable candidates highlight in the minibuffer." - :global t - :group 'minibuffer - (cond - (completions-highlight-mode - (setq completions--overlay (make-overlay 0 0)) - (overlay-put completions--overlay 'face 'completions-highlight) - (add-hook 'completion-setup-hook #'completions-highlight--setup-hook t)) - (t - (remove-hook 'completion-setup-hook #'completions-highlight--setup-hook))) - (completions-highlight--delete)) +(defcustom completions-highlight-face 'completions-highlight + "A face name to highlight current completion candidate. +If the value is nil no highlight is performed." + :type '(choice (const nil) face) + :version "29.1") (defvar completion-extra-properties nil "Property list of extra properties of the current completion job. -- 2.39.2