;;;###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)
;;; 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
(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)))
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