emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 7f5db3f: * lisp/emacs-lisp/cursor-sensor.el: Make i


From: Stefan Monnier
Subject: [Emacs-diffs] master 7f5db3f: * lisp/emacs-lisp/cursor-sensor.el: Make it possible to reveal invisible text
Date: Mon, 21 Oct 2019 16:35:45 -0400 (EDT)

branch: master
commit 7f5db3f40caa3050135dae85294849f8375d97b8
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/emacs-lisp/cursor-sensor.el: Make it possible to reveal invisible 
text
    
    (cursor-sensor-mode): Hook into post-command-hook as well.
    (cursor-sensor--detect): Make argument optional.
---
 lisp/emacs-lisp/cursor-sensor.el | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/lisp/emacs-lisp/cursor-sensor.el b/lisp/emacs-lisp/cursor-sensor.el
index 66b940f..21d22bb 100644
--- a/lisp/emacs-lisp/cursor-sensor.el
+++ b/lisp/emacs-lisp/cursor-sensor.el
@@ -132,7 +132,7 @@ By convention, this is a list of symbols where each symbol 
stands for the
 ;;;###autoload
 (define-minor-mode cursor-intangible-mode
   "Keep cursor outside of any `cursor-intangible' text property."
-  nil nil nil
+  :global nil
   (if cursor-intangible-mode
       (add-hook 'pre-redisplay-functions #'cursor-sensor--move-to-tangible
                 nil t)
@@ -140,7 +140,7 @@ By convention, this is a list of symbols where each symbol 
stands for the
 
 ;;; Detect cursor movement.
 
-(defun cursor-sensor--detect (window)
+(defun cursor-sensor--detect (&optional window)
   (unless cursor-sensor-inhibit
     (let* ((point (window-point window))
            ;; It's often desirable to make the cursor-sensor-functions property
@@ -178,7 +178,8 @@ By convention, this is a list of symbols where each symbol 
stands for the
                       (unless (memq f (get-char-property
                                        pos 'cursor-sensor-functions))
                         (setq missing t)))
-                    missing))))
+                    missing)))
+               (window (selected-window)))
           (dolist (f (cdr old))
             (unless (and (memq f new) (not (funcall missing-p f)))
               (funcall f window oldpos 'left)))
@@ -203,12 +204,21 @@ of the cursor.  They're called with three arguments 
(WINDOW OLDPOS DIR)
 where WINDOW is the affected window, OLDPOS is the last known position of
 the cursor and DIR can be `entered' or `left' depending on whether the cursor
 is entering the area covered by the text-property property or leaving it."
-  nil nil nil
-  (if cursor-sensor-mode
-      (add-hook 'pre-redisplay-functions #'cursor-sensor--detect
-                nil t)
+  :global nil
+  (cond
+   (cursor-sensor-mode
+    ;; Also add ourselves to `post-command-hook' because
+    ;; `pre-redisplay-functions' are sometimes called too late (after
+    ;; adjust_point_for_property has moved point, which makes it
+    ;; "impossible" for cursor-sensor-functions to do things like
+    ;; revealing invisible text).
+    (add-hook 'post-command-hook #'cursor-sensor--detect nil t)
+    (add-hook 'pre-redisplay-functions #'cursor-sensor--detect
+              nil t))
+   (t
+    (remove-hook 'post-command-hook #'cursor-sensor--detect t)
     (remove-hook  'pre-redisplay-functions #'cursor-sensor--detect
-                t)))
+                t))))
 
 (provide 'cursor-sensor)
 ;;; cursor-sensor.el ends here



reply via email to

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