aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2020-02-24 09:55:09 -0500
committerStefan Monnier2020-02-24 09:55:09 -0500
commite74fb4688b78f549fbc79a2163c92ba64296ee3d (patch)
treea380887f78193608e63ca708e3f9ebd6eb99658b
parent3bce7ec3826003fda1971224a20d7fe2cba8bf65 (diff)
downloademacs-e74fb4688b78f549fbc79a2163c92ba64296ee3d.tar.gz
emacs-e74fb4688b78f549fbc79a2163c92ba64296ee3d.zip
* lisp/emacs-lisp/cursor-sensor.el (cursor-sensor--detect): Change last fix
Make sure we always work in the selected-window's buffer.
-rw-r--r--lisp/emacs-lisp/cursor-sensor.el112
1 files changed, 57 insertions, 55 deletions
diff --git a/lisp/emacs-lisp/cursor-sensor.el b/lisp/emacs-lisp/cursor-sensor.el
index 7728e78c471..d50f7ad0be5 100644
--- a/lisp/emacs-lisp/cursor-sensor.el
+++ b/lisp/emacs-lisp/cursor-sensor.el
@@ -141,61 +141,63 @@ By convention, this is a list of symbols where each symbol stands for the
141;;; Detect cursor movement. 141;;; Detect cursor movement.
142 142
143(defun cursor-sensor--detect (&optional window) 143(defun cursor-sensor--detect (&optional window)
144 (unless cursor-sensor-inhibit 144 (with-current-buffer (window-buffer window)
145 (let* ((point (window-point window)) 145 (unless cursor-sensor-inhibit
146 ;; It's often desirable to make the cursor-sensor-functions property 146 (let* ((point (window-point window))
147 ;; non-sticky on both ends, but that means get-pos-property might 147 ;; It's often desirable to make the
148 ;; never see it. 148 ;; cursor-sensor-functions property non-sticky on both
149 (new (and (eq (current-buffer) (window-buffer)) 149 ;; ends, but that means get-pos-property might never
150 (or (get-char-property point 'cursor-sensor-functions) 150 ;; see it.
151 (unless (<= (point-min) point) 151 (new (or (get-char-property point 'cursor-sensor-functions)
152 (get-char-property (1- point) 'cursor-sensor-functions))))) 152 (unless (<= (point-min) point)
153 (old (window-parameter window 'cursor-sensor--last-state)) 153 (get-char-property (1- point)
154 (oldposmark (car old)) 154 'cursor-sensor-functions))))
155 (oldpos (or (if oldposmark (marker-position oldposmark)) 155 (old (window-parameter window 'cursor-sensor--last-state))
156 (point-min))) 156 (oldposmark (car old))
157 (start (min oldpos point)) 157 (oldpos (or (if oldposmark (marker-position oldposmark))
158 (end (max oldpos point))) 158 (point-min)))
159 (unless (or (null old) (eq (marker-buffer oldposmark) (current-buffer))) 159 (start (min oldpos point))
160 ;; `window' does not display the same buffer any more! 160 (end (max oldpos point)))
161 (setcdr old nil)) 161 (unless (or (null old) (eq (marker-buffer oldposmark) (current-buffer)))
162 (if (or (and (null new) (null (cdr old))) 162 ;; `window' does not display the same buffer any more!
163 (and (eq new (cdr old)) 163 (setcdr old nil))
164 (eq (next-single-char-property-change 164 (if (or (and (null new) (null (cdr old)))
165 start 'cursor-sensor-functions nil end) 165 (and (eq new (cdr old))
166 end))) 166 (eq (next-single-char-property-change
167 ;; Clearly nothing to do. 167 start 'cursor-sensor-functions nil end)
168 nil 168 end)))
169 ;; Maybe something to do. Let's see exactly what needs to run. 169 ;; Clearly nothing to do.
170 (let* ((missing-p 170 nil
171 (lambda (f) 171 ;; Maybe something to do. Let's see exactly what needs to run.
172 "Non-nil if F is missing somewhere between START and END." 172 (let* ((missing-p
173 (let ((pos start) 173 (lambda (f)
174 (missing nil)) 174 "Non-nil if F is missing somewhere between START and END."
175 (while (< pos end) 175 (let ((pos start)
176 (setq pos (next-single-char-property-change 176 (missing nil))
177 pos 'cursor-sensor-functions 177 (while (< pos end)
178 nil end)) 178 (setq pos (next-single-char-property-change
179 (unless (memq f (get-char-property 179 pos 'cursor-sensor-functions
180 pos 'cursor-sensor-functions)) 180 nil end))
181 (setq missing t))) 181 (unless (memq f (get-char-property
182 missing))) 182 pos 'cursor-sensor-functions))
183 (window (selected-window))) 183 (setq missing t)))
184 (dolist (f (cdr old)) 184 missing)))
185 (unless (and (memq f new) (not (funcall missing-p f))) 185 (window (selected-window)))
186 (funcall f window oldpos 'left))) 186 (dolist (f (cdr old))
187 (dolist (f new) 187 (unless (and (memq f new) (not (funcall missing-p f)))
188 (unless (and (memq f (cdr old)) (not (funcall missing-p f))) 188 (funcall f window oldpos 'left)))
189 (funcall f window oldpos 'entered))))) 189 (dolist (f new)
190 190 (unless (and (memq f (cdr old)) (not (funcall missing-p f)))
191 ;; Remember current state for next time. 191 (funcall f window oldpos 'entered)))))
192 ;; Re-read cursor-sensor-functions since the functions may have moved 192
193 ;; window-point! 193 ;; Remember current state for next time.
194 (if old 194 ;; Re-read cursor-sensor-functions since the functions may have moved
195 (progn (move-marker (car old) point) 195 ;; window-point!
196 (setcdr old new)) 196 (if old
197 (set-window-parameter window 'cursor-sensor--last-state 197 (progn (move-marker (car old) point)
198 (cons (copy-marker point) new)))))) 198 (setcdr old new))
199 (set-window-parameter window 'cursor-sensor--last-state
200 (cons (copy-marker point) new)))))))
199 201
200;;;###autoload 202;;;###autoload
201(define-minor-mode cursor-sensor-mode 203(define-minor-mode cursor-sensor-mode