diff options
Diffstat (limited to 'lisp/emacs-lisp/cursor-sensor.el')
-rw-r--r-- | lisp/emacs-lisp/cursor-sensor.el | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/cursor-sensor.el b/lisp/emacs-lisp/cursor-sensor.el index a21d78998ac..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 @@ -160,7 +160,7 @@ By convention, this is a list of symbols where each symbol stands for the (setcdr old nil)) (if (or (and (null new) (null (cdr old))) (and (eq new (cdr old)) - (eq (next-single-property-change + (eq (next-single-char-property-change start 'cursor-sensor-functions nil end) end))) ;; Clearly nothing to do. @@ -172,13 +172,14 @@ By convention, this is a list of symbols where each symbol stands for the (let ((pos start) (missing nil)) (while (< pos end) - (setq pos (next-single-property-change + (setq pos (next-single-char-property-change pos 'cursor-sensor-functions nil end)) (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 |