diff options
| author | Stefan Monnier | 2026-03-20 23:18:29 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2026-03-20 23:18:29 -0400 |
| commit | f986e5a8979cf48ff2c1ffa0ee3bdce10868b8ff (patch) | |
| tree | 610cb25257800d1200678cbb05ebcc3cd0fab29b /lisp | |
| parent | 378cfb866054f4bc315cc5b6c245872056d8caec (diff) | |
| download | emacs-f986e5a8979cf48ff2c1ffa0ee3bdce10868b8ff.tar.gz emacs-f986e5a8979cf48ff2c1ffa0ee3bdce10868b8ff.zip | |
cursor-sensor.el: Partial fix for bug#80255
This provides limited support for window-specific overlay properties.
To complete it, we still need to add support for it to
`next/previous-single-char-property-change`.
* lisp/emacs-lisp/cursor-sensor.el (cursor-sensor--intangible-p):
Add `window` argument.
(cursor-sensor-tangible-pos, cursor-sensor--detect):
Pass `window` argument to the functions
looking for overlay properties.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/cursor-sensor.el | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/lisp/emacs-lisp/cursor-sensor.el b/lisp/emacs-lisp/cursor-sensor.el index cd672ba68c9..e85f0da4b48 100644 --- a/lisp/emacs-lisp/cursor-sensor.el +++ b/lisp/emacs-lisp/cursor-sensor.el | |||
| @@ -67,13 +67,14 @@ | |||
| 67 | By convention, this is a list of symbols where each symbol stands for the | 67 | By convention, this is a list of symbols where each symbol stands for the |
| 68 | \"cause\" of the suspension.") | 68 | \"cause\" of the suspension.") |
| 69 | 69 | ||
| 70 | (defun cursor-sensor--intangible-p (pos) | 70 | (defun cursor-sensor--intangible-p (pos &optional window) |
| 71 | (let ((p (get-pos-property pos 'cursor-intangible))) | 71 | (let ((p (get-pos-property pos 'cursor-intangible window))) |
| 72 | (if p | 72 | (if p |
| 73 | (let (a b) | 73 | (let (a b) |
| 74 | (if (and (setq a (get-char-property pos 'cursor-intangible)) | 74 | (if (and (setq a (get-char-property pos 'cursor-intangible window)) |
| 75 | (setq b (if (> pos (point-min)) | 75 | (setq b (if (> pos (point-min)) |
| 76 | (get-char-property (1- pos) 'cursor-intangible))) | 76 | (get-char-property (1- pos) 'cursor-intangible |
| 77 | window))) | ||
| 77 | (not (eq a b))) | 78 | (not (eq a b))) |
| 78 | ;; If we're right between two different intangible thingies, | 79 | ;; If we're right between two different intangible thingies, |
| 79 | ;; we can stop here. This is not quite consistent with the | 80 | ;; we can stop here. This is not quite consistent with the |
| @@ -84,27 +85,32 @@ By convention, this is a list of symbols where each symbol stands for the | |||
| 84 | p))) | 85 | p))) |
| 85 | 86 | ||
| 86 | (defun cursor-sensor-tangible-pos (curpos window) | 87 | (defun cursor-sensor-tangible-pos (curpos window) |
| 87 | (when (cursor-sensor--intangible-p curpos) | 88 | (when (cursor-sensor--intangible-p curpos window) |
| 88 | ;; Find the two nearest tangible positions. | 89 | ;; Find the two nearest tangible positions. |
| 89 | (let ((nextpos curpos) | 90 | (let ((nextpos curpos) |
| 90 | (prevpos curpos) | 91 | (prevpos curpos) |
| 91 | (oldpos (window-parameter window 'cursor-intangible--last-point))) | 92 | (oldpos (window-parameter window 'cursor-intangible--last-point))) |
| 92 | (while (if (>= nextpos (point-max)) | 93 | (while (if (>= nextpos (point-max)) |
| 93 | (when (cursor-sensor--intangible-p nextpos) (setq nextpos nil)) | 94 | (when (cursor-sensor--intangible-p nextpos window) |
| 95 | (setq nextpos nil)) | ||
| 94 | (setq nextpos | 96 | (setq nextpos |
| 95 | (if (get-char-property nextpos 'cursor-intangible) | 97 | (if (get-char-property nextpos 'cursor-intangible window) |
| 96 | (next-single-char-property-change | 98 | (next-single-char-property-change |
| 97 | nextpos 'cursor-intangible nil (point-max)) | 99 | nextpos 'cursor-intangible nil ;;FIXME: window |
| 100 | (point-max)) | ||
| 98 | (1+ nextpos))) | 101 | (1+ nextpos))) |
| 99 | (cursor-sensor--intangible-p nextpos))) | 102 | (cursor-sensor--intangible-p nextpos window))) |
| 100 | (while (if (<= prevpos (point-min)) | 103 | (while (if (<= prevpos (point-min)) |
| 101 | (when (cursor-sensor--intangible-p prevpos) (setq prevpos nil)) | 104 | (when (cursor-sensor--intangible-p prevpos window) |
| 105 | (setq prevpos nil)) | ||
| 102 | (setq prevpos | 106 | (setq prevpos |
| 103 | (if (get-char-property (1- prevpos) 'cursor-intangible) | 107 | (if (get-char-property (1- prevpos) |
| 108 | 'cursor-intangible window) | ||
| 104 | (previous-single-char-property-change | 109 | (previous-single-char-property-change |
| 105 | prevpos 'cursor-intangible nil (point-min)) | 110 | prevpos 'cursor-intangible nil ;;FIXME: window |
| 111 | (point-min)) | ||
| 106 | (1- prevpos))) | 112 | (1- prevpos))) |
| 107 | (cursor-sensor--intangible-p prevpos))) | 113 | (cursor-sensor--intangible-p prevpos window))) |
| 108 | ;; Pick the preferred one depending on the direction of the motion. | 114 | ;; Pick the preferred one depending on the direction of the motion. |
| 109 | ;; Goals, from most important to least important: | 115 | ;; Goals, from most important to least important: |
| 110 | ;; - Prefer a tangible position. | 116 | ;; - Prefer a tangible position. |
| @@ -146,6 +152,7 @@ By convention, this is a list of symbols where each symbol stands for the | |||
| 146 | ;;; Detect cursor movement. | 152 | ;;; Detect cursor movement. |
| 147 | 153 | ||
| 148 | (defun cursor-sensor--detect (&optional window) | 154 | (defun cursor-sensor--detect (&optional window) |
| 155 | (unless window (setq window (selected-window))) | ||
| 149 | ;; We're run from `pre-redisplay-functions' and `post-command-hook' | 156 | ;; We're run from `pre-redisplay-functions' and `post-command-hook' |
| 150 | ;; where we can't handle errors very well, so just demote them to make | 157 | ;; where we can't handle errors very well, so just demote them to make |
| 151 | ;; sure they don't get in the way. | 158 | ;; sure they don't get in the way. |
| @@ -158,11 +165,12 @@ By convention, this is a list of symbols where each symbol stands for the | |||
| 158 | ;; ends, so we can't use just `get-pos-property' because it | 165 | ;; ends, so we can't use just `get-pos-property' because it |
| 159 | ;; might never see it. | 166 | ;; might never see it. |
| 160 | ;; FIXME: Combine properties from covering overlays? | 167 | ;; FIXME: Combine properties from covering overlays? |
| 161 | (new (or (get-pos-property point 'cursor-sensor-functions) | 168 | (new (or (get-pos-property point 'cursor-sensor-functions window) |
| 162 | (get-char-property point 'cursor-sensor-functions) | 169 | (get-char-property point |
| 170 | 'cursor-sensor-functions window) | ||
| 163 | (unless (<= (point-min) point) | 171 | (unless (<= (point-min) point) |
| 164 | (get-char-property (1- point) | 172 | (get-char-property (1- point) |
| 165 | 'cursor-sensor-functions)))) | 173 | 'cursor-sensor-functions window)))) |
| 166 | (old (window-parameter window 'cursor-sensor--last-state)) | 174 | (old (window-parameter window 'cursor-sensor--last-state)) |
| 167 | (oldposmark (car old)) | 175 | (oldposmark (car old)) |
| 168 | (oldpos (or (if oldposmark (marker-position oldposmark)) | 176 | (oldpos (or (if oldposmark (marker-position oldposmark)) |
| @@ -184,13 +192,13 @@ By convention, this is a list of symbols where each symbol stands for the | |||
| 184 | (missing nil)) | 192 | (missing nil)) |
| 185 | (while (< (setq pos (next-single-char-property-change | 193 | (while (< (setq pos (next-single-char-property-change |
| 186 | pos 'cursor-sensor-functions | 194 | pos 'cursor-sensor-functions |
| 187 | nil end)) | 195 | nil ;;FIXME: window |
| 196 | end)) | ||
| 188 | end) | 197 | end) |
| 189 | (unless (memq f (get-char-property | 198 | (unless (memq f (get-char-property |
| 190 | pos 'cursor-sensor-functions)) | 199 | pos 'cursor-sensor-functions window)) |
| 191 | (setq missing t))) | 200 | (setq missing t))) |
| 192 | missing))) | 201 | missing)))) |
| 193 | (window (selected-window))) | ||
| 194 | (dolist (f (cdr old)) | 202 | (dolist (f (cdr old)) |
| 195 | (unless (and (memq f new) (not (funcall missing-p f))) | 203 | (unless (and (memq f new) (not (funcall missing-p f))) |
| 196 | (funcall f window oldpos 'left))) | 204 | (funcall f window oldpos 'left))) |