emacs-diffs
[Top][All Lists]
Advanced

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

feature/completions-customs c1ea52f4ad: Improve cursor-face-highlight-mo


From: Jimmy Aguilar Mena
Subject: feature/completions-customs c1ea52f4ad: Improve cursor-face-highlight-mode a bit more.
Date: Sun, 13 Mar 2022 22:07:41 -0400 (EDT)

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

    Improve cursor-face-highlight-mode a bit more.
    
    Add the hook locally to the buffer only when needed to avoid even
    calling the function redisplay--update-cursor-face-highlight when the
    mode is enabled.
    
    * lisp/simple.el (redisplay--update-cursor-face-highlight) : Remove
    unneeded condition.
    (cursor-face-highlight-mode) : Conditionally add or remove
    redisplay--update-cursor-face-highlight to pre-redisplay-functions with
    buffer local flag.
---
 lisp/simple.el | 52 ++++++++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 02f05ccb04..cada2e5571 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6540,37 +6540,41 @@ The overlay is returned by the function.")
         (unless (equal new rol)
           (set-window-parameter window 'internal-region-overlay new))))))
 
-(define-minor-mode cursor-face-highlight-mode
-  "When enabled the cursor-face property is respected.")
-
 (defun redisplay--update-cursor-face-highlight (window)
   "Highlights the overlay used to highlight text with cursor-face."
-  (when cursor-face-highlight-mode
-    (let ((rol (window-parameter window 'internal-cursor-face-overlay)))
-      (if-let (((or (eq window (selected-window))
-                    (and (window-minibuffer-p)
-                         (eq window (minibuffer-selected-window)))))
-               (pt (window-point window))
-               (value (get-text-property pt 'cursor-face))
-               ;; Extra code needed here for when passing plists.
-               (cursor-face (if (facep value) value)))
-          (let* ((start (previous-single-property-change
-                         (1+ pt) 'cursor-face nil (point-min)))
-                 (end (next-single-property-change
-                       pt 'cursor-face nil (point-max)))
-                 (new (redisplay--highlight-overlay-function
-                       start end window rol cursor-face)))
-            (unless (equal new rol)
-              (set-window-parameter window 'internal-cursor-face-overlay new)))
-        (redisplay--unhighlight-overlay-function rol)))))
-
-(defvar pre-redisplay-functions (list #'redisplay--update-cursor-face-highlight
-                                      #'redisplay--update-region-highlight)
+  (let ((rol (window-parameter window 'internal-cursor-face-overlay)))
+    (if-let (((or (eq window (selected-window))
+                  (and (window-minibuffer-p)
+                       (eq window (minibuffer-selected-window)))))
+             (pt (window-point window))
+             (value (get-text-property pt 'cursor-face))
+             ;; Extra code needed here for when passing plists.
+             (cursor-face (if (facep value) value)))
+        (let* ((start (previous-single-property-change
+                       (1+ pt) 'cursor-face nil (point-min)))
+               (end (next-single-property-change
+                     pt 'cursor-face nil (point-max)))
+               (new (redisplay--highlight-overlay-function
+                     start end window rol cursor-face)))
+          (unless (equal new rol)
+            (set-window-parameter window 'internal-cursor-face-overlay new)))
+      (redisplay--unhighlight-overlay-function rol))))
+
+(defvar pre-redisplay-functions (list #'redisplay--update-region-highlight)
   "Hook run just before redisplay.
 It is called in each window that is to be redisplayed.  It takes one argument,
 which is the window that will be redisplayed.  When run, the `current-buffer'
 is set to the buffer displayed in that window.")
 
+(define-minor-mode cursor-face-highlight-mode
+  "When enabled the cursor-face property is respected."
+  :global nil
+  (if cursor-face-highlight-mode
+      (add-hook 'pre-redisplay-functions
+                #'redisplay--update-cursor-face-highlight nil t)
+    (add-hook 'pre-redisplay-functions
+              #'redisplay--update-cursor-face-highlight)))
+
 (defun redisplay--pre-redisplay-functions (windows)
   (with-demoted-errors "redisplay--pre-redisplay-functions: %S"
     (if (null windows)



reply via email to

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