From 7f5db3f40caa3050135dae85294849f8375d97b8 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 21 Oct 2019 16:35:38 -0400 Subject: [PATCH] * 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 66b940f7fb3..21d22bbac98 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 -- 2.39.2