emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/completions-customs e683e60fad 3/3: Add new mode completions-hig


From: Jimmy Aguilar Mena
Subject: feature/completions-customs e683e60fad 3/3: Add new mode completions-highlight-mode.
Date: Thu, 10 Mar 2022 08:42:43 -0500 (EST)

branch: feature/completions-customs
commit e683e60fad69914eb0c33c9ad83b819b160fd5a2
Author: Jimmy Aguilar Mena <spacibba@aol.com>
Commit: Jimmy Aguilar Mena <spacibba@aol.com>

    Add new mode completions-highlight-mode.
---
 doc/emacs/mini.texi |  5 +++++
 etc/NEWS            |  3 +++
 lisp/minibuffer.el  | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi
index eb2bfce136..afacb9c7cd 100644
--- a/doc/emacs/mini.texi
+++ b/doc/emacs/mini.texi
@@ -665,6 +665,11 @@ mode, header line and a bottom divider, if any.  For a 
more complex
 control of the Completion window display properties you can use
 @code{display-buffer-alist} (@pxref{Buffer Display Action Alists}).
 
+@vindex completions-highlight-mode
+When the mode @{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}.
+
 @node Minibuffer History
 @section Minibuffer History
 @cindex minibuffer history
diff --git a/etc/NEWS b/etc/NEWS
index 5a0d6c8fdb..05f219ca03 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -565,6 +565,9 @@ some completion is made.
 *** New user option 'completions-max-height'.
 This option limits the height of the "*Completions*" buffer.
 
+*** New mode completions-highlight.
+This mode highlights the current candidate in the *Completions* buffer
+with the completions-highlight face.
 
 ** Isearch and Replace
 
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index cd0c274765..148ba7a873 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2138,6 +2138,52 @@ candidates."
   (run-hooks 'completion-setup-hook)
   nil)
 
+
+(defface completions-highlight
+  '((t :inherit highlight :extend t))
+  "Default face for highlighting the current line in Hl-Line 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* when 
``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))
+
 (defvar completion-extra-properties nil
   "Property list of extra properties of the current completion job.
 These include:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]