From: Jimmy Aguilar Mena Date: Mon, 14 Mar 2022 01:55:27 +0000 (+0100) Subject: Improve cursor-face-highlight-mode a bit more. X-Git-Tag: emacs-29.0.90~1931^2~1002^2~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c1ea52f4ad2e673e364ca8565938ba3584126556;p=emacs.git 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. --- diff --git a/lisp/simple.el b/lisp/simple.el index 02f05ccb041..cada2e5571a 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)