diff options
| author | Stefan Monnier | 2019-10-21 16:35:38 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-10-21 16:35:38 -0400 |
| commit | 7f5db3f40caa3050135dae85294849f8375d97b8 (patch) | |
| tree | 54bd5553718d7db27b4a627d6f3f4e04f830fe74 | |
| parent | cf294d78a1d25c5c5178ce3fc7fdddc0de58b904 (diff) | |
| download | emacs-7f5db3f40caa3050135dae85294849f8375d97b8.tar.gz emacs-7f5db3f40caa3050135dae85294849f8375d97b8.zip | |
* 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.
| -rw-r--r-- | lisp/emacs-lisp/cursor-sensor.el | 26 |
1 files 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 | |||
| 132 | ;;;###autoload | 132 | ;;;###autoload |
| 133 | (define-minor-mode cursor-intangible-mode | 133 | (define-minor-mode cursor-intangible-mode |
| 134 | "Keep cursor outside of any `cursor-intangible' text property." | 134 | "Keep cursor outside of any `cursor-intangible' text property." |
| 135 | nil nil nil | 135 | :global nil |
| 136 | (if cursor-intangible-mode | 136 | (if cursor-intangible-mode |
| 137 | (add-hook 'pre-redisplay-functions #'cursor-sensor--move-to-tangible | 137 | (add-hook 'pre-redisplay-functions #'cursor-sensor--move-to-tangible |
| 138 | nil t) | 138 | nil t) |
| @@ -140,7 +140,7 @@ By convention, this is a list of symbols where each symbol stands for the | |||
| 140 | 140 | ||
| 141 | ;;; Detect cursor movement. | 141 | ;;; Detect cursor movement. |
| 142 | 142 | ||
| 143 | (defun cursor-sensor--detect (window) | 143 | (defun cursor-sensor--detect (&optional window) |
| 144 | (unless cursor-sensor-inhibit | 144 | (unless cursor-sensor-inhibit |
| 145 | (let* ((point (window-point window)) | 145 | (let* ((point (window-point window)) |
| 146 | ;; It's often desirable to make the cursor-sensor-functions property | 146 | ;; 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 | |||
| 178 | (unless (memq f (get-char-property | 178 | (unless (memq f (get-char-property |
| 179 | pos 'cursor-sensor-functions)) | 179 | pos 'cursor-sensor-functions)) |
| 180 | (setq missing t))) | 180 | (setq missing t))) |
| 181 | missing)))) | 181 | missing))) |
| 182 | (window (selected-window))) | ||
| 182 | (dolist (f (cdr old)) | 183 | (dolist (f (cdr old)) |
| 183 | (unless (and (memq f new) (not (funcall missing-p f))) | 184 | (unless (and (memq f new) (not (funcall missing-p f))) |
| 184 | (funcall f window oldpos 'left))) | 185 | (funcall f window oldpos 'left))) |
| @@ -203,12 +204,21 @@ of the cursor. They're called with three arguments (WINDOW OLDPOS DIR) | |||
| 203 | where WINDOW is the affected window, OLDPOS is the last known position of | 204 | where WINDOW is the affected window, OLDPOS is the last known position of |
| 204 | the cursor and DIR can be `entered' or `left' depending on whether the cursor | 205 | the cursor and DIR can be `entered' or `left' depending on whether the cursor |
| 205 | is entering the area covered by the text-property property or leaving it." | 206 | is entering the area covered by the text-property property or leaving it." |
| 206 | nil nil nil | 207 | :global nil |
| 207 | (if cursor-sensor-mode | 208 | (cond |
| 208 | (add-hook 'pre-redisplay-functions #'cursor-sensor--detect | 209 | (cursor-sensor-mode |
| 209 | nil t) | 210 | ;; Also add ourselves to `post-command-hook' because |
| 211 | ;; `pre-redisplay-functions' are sometimes called too late (after | ||
| 212 | ;; adjust_point_for_property has moved point, which makes it | ||
| 213 | ;; "impossible" for cursor-sensor-functions to do things like | ||
| 214 | ;; revealing invisible text). | ||
| 215 | (add-hook 'post-command-hook #'cursor-sensor--detect nil t) | ||
| 216 | (add-hook 'pre-redisplay-functions #'cursor-sensor--detect | ||
| 217 | nil t)) | ||
| 218 | (t | ||
| 219 | (remove-hook 'post-command-hook #'cursor-sensor--detect t) | ||
| 210 | (remove-hook 'pre-redisplay-functions #'cursor-sensor--detect | 220 | (remove-hook 'pre-redisplay-functions #'cursor-sensor--detect |
| 211 | t))) | 221 | t)))) |
| 212 | 222 | ||
| 213 | (provide 'cursor-sensor) | 223 | (provide 'cursor-sensor) |
| 214 | ;;; cursor-sensor.el ends here | 224 | ;;; cursor-sensor.el ends here |