]> git.eshelyaron.com Git - emacs.git/commitdiff
In follow mode windows in a GUI, don't display inactive cursors
authorAlan Mackenzie <acm@muc.de>
Fri, 19 Oct 2018 09:54:31 +0000 (09:54 +0000)
committerAlan Mackenzie <acm@muc.de>
Fri, 19 Oct 2018 09:54:31 +0000 (09:54 +0000)
This is done by setting cursor-in-non-selected-windows buffer locally.

* lisp/follow.el (follow-hide-ghost-cursors): New customizable option.
(follow-mode): Create and set, or kill buffer-local copy of
cursor-in-non-selected-windows when the mode gets enabled or disabled.
(follow-prev-buffer): New variable.
(follow-adjust-window): Manipulate cursor-in-non-selected-windows when the
current buffer changes, to ensure that cursors stay visible in non-selected
follow window groups.

* etc/NEWS: Add an entry for this change.

etc/NEWS
lisp/follow.el

index 2ebe5a16a22d629c485acf3aaf25a8d9cb88e75d..f1be50babd630990633275dd58f5ec67d8ee74ed 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -287,6 +287,12 @@ in (info "(emacs) Directory Variables")
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
+---
+** Follow mode
+In the current follow group of windows, "ghost" cursors are no longer
+displayed in the non-selected follow windows.  To get the old behavior
+back, customize follow-hide-ghost-cursors to nil.
+
 ** Octave mode
 The mode is automatically enabled in files that start with the
 'function' keyword.
index b44df423d608febe120e95759ade233133025f12..ed7b7d2359d5a689ef8941920415b7c5b5f2d10f 100644 (file)
@@ -311,6 +311,17 @@ are \" Fw\", or simply \"\"."
           (remove-hook 'find-file-hook 'follow-find-file-hook))
         (set-default symbol value)))
 
+(defcustom follow-hide-ghost-cursors t  ; Maybe this should be nil.
+  "When non-nil, Follow mode attempts to hide the obtrusive cursors
+in the non-selected windows of a window group.
+
+This variable takes effect when `follow-mode' is initialized.
+
+Due to limitations in Emacs, this only operates on the followers
+of the selected window."
+  :type 'boolean
+  :group 'follow)
+
 (defvar follow-cache-command-list
   '(next-line previous-line forward-char backward-char right-char left-char)
   "List of commands that don't require recalculation.
@@ -427,6 +438,8 @@ Keys specific to Follow mode:
 
         (when isearch-lazy-highlight
           (setq-local isearch-lazy-highlight 'all-windows))
+        (when follow-hide-ghost-cursors
+          (setq-local cursor-in-non-selected-windows nil))
 
         (setq window-group-start-function 'follow-window-start)
         (setq window-group-end-function 'follow-window-end)
@@ -456,6 +469,8 @@ Keys specific to Follow mode:
     (kill-local-variable 'window-group-end-function)
     (kill-local-variable 'window-group-start-function)
 
+    (kill-local-variable 'cursor-in-non-selected-windows)
+
     (remove-hook 'ispell-update-post-hook 'follow-post-command-hook t)
     (remove-hook 'replace-update-post-hook 'follow-post-command-hook t)
     (remove-hook 'isearch-update-post-hook 'follow-post-command-hook t)
@@ -1262,6 +1277,10 @@ non-first windows in Follow mode."
 
 ;;; Pre Display Function
 
+(defvar follow-prev-buffer nil
+  "The buffer current at the last call to `follow-adjust-window' or nil.
+follow-mode is not necessarily enabled in this buffer.")
+
 ;; This function is added to `pre-display-function' and is thus called
 ;; before each redisplay operation.  It supersedes (2018-09) the
 ;; former use of the post command hook, and now does the right thing
@@ -1310,6 +1329,24 @@ non-first windows in Follow mode."
 (defun follow-adjust-window (win)
   ;; Adjust the window WIN and its followers.
   (cl-assert (eq (window-buffer win) (current-buffer)))
+
+  ;; Have we moved out of or into a follow-mode window group?
+  ;; If so, attend to the visibility of the cursors.
+  (when (not (eq (current-buffer) follow-prev-buffer))
+    ;; Do we need to switch off cursor handling in the previous buffer?
+    (when (buffer-live-p follow-prev-buffer)
+      (with-current-buffer follow-prev-buffer
+        (when (and follow-mode
+                   (local-variable-p 'cursor-in-non-selected-windows))
+          (setq cursor-in-non-selected-windows
+                (default-value 'cursor-in-non-selected-windows)))))
+    ;; Do we need to switch on cursor handling in the current buffer?
+    (when (and follow-mode
+               (local-variable-p 'cursor-in-non-selected-windows))
+      (setq cursor-in-non-selected-windows nil))
+    (when (buffer-live-p (current-buffer))
+      (setq follow-prev-buffer (current-buffer))))
+
   (when (and follow-mode
              (not (window-minibuffer-p win)))
     (let ((windows (follow-all-followers win)))