summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2020-03-04 13:57:56 -0800
committerGlenn Morris <rgm@gnu.org>2020-03-04 13:57:56 -0800
commit1c81bb8c24054c5e519dbff138e26042fdb74956 (patch)
treeb632283b4cf4a36f19b309aa0a46090cc0e89e8f /lisp/emacs-lisp
parentdc3006cf1419e5b22c35fa36d79ba029d0482df1 (diff)
parent5b7d226779282f01b52fc6308fcf9f4e84c40679 (diff)
downloademacs-1c81bb8c24054c5e519dbff138e26042fdb74956.tar.gz
emacs-1c81bb8c24054c5e519dbff138e26042fdb74956.tar.bz2
emacs-1c81bb8c24054c5e519dbff138e26042fdb74956.zip
Merge from origin/emacs-27
5b7d226779 * etc/AUTHORS: Update. 4aa758e53d ; ChangeLog.3 update 9261b1ed49 * admin/authors.el (authors-ignored-files): Fix entries. 86e4da6eaf ; ChangeLog.3 update 009c6a1767 ; ChangeLog.3 fixes f9e53947c7 Fix documented slot name of eieio-instance-tracker class 999d75c0c1 Range-check width passed to define-fringe-bitmap 29e415d6b0 ; ChangeLog.3 fixes 4653baa6a5 ; ChangeLog.3 update & fixes. a95ec6e060 * admin/authors.el: Add missing entries af519a6348 Define libgnutls-version properly 9ec6eb1065 vc-dir-ignore: More accurately choose base directory e74fb4688b * lisp/emacs-lisp/cursor-sensor.el (cursor-sensor--detect)... 3bce7ec382 CC Mode: Protect against consecutive calls to before-chang...
Diffstat (limited to 'lisp/emacs-lisp')
-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
;;; Detect cursor movement.
(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
- ;; non-sticky on both ends, but that means get-pos-property might
- ;; never see it.
- (new (and (eq (current-buffer) (window-buffer))
- (or (get-char-property point 'cursor-sensor-functions)
- (unless (<= (point-min) point)
- (get-char-property (1- point) 'cursor-sensor-functions)))))
- (old (window-parameter window 'cursor-sensor--last-state))
- (oldposmark (car old))
- (oldpos (or (if oldposmark (marker-position oldposmark))
- (point-min)))
- (start (min oldpos point))
- (end (max oldpos point)))
- (unless (or (null old) (eq (marker-buffer oldposmark) (current-buffer)))
- ;; `window' does not display the same buffer any more!
- (setcdr old nil))
- (if (or (and (null new) (null (cdr old)))
- (and (eq new (cdr old))
- (eq (next-single-char-property-change
- start 'cursor-sensor-functions nil end)
- end)))
- ;; Clearly nothing to do.
- nil
- ;; Maybe something to do. Let's see exactly what needs to run.
- (let* ((missing-p
- (lambda (f)
- "Non-nil if F is missing somewhere between START and END."
- (let ((pos start)
- (missing nil))
- (while (< pos end)
- (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)))
- (window (selected-window)))
- (dolist (f (cdr old))
- (unless (and (memq f new) (not (funcall missing-p f)))
- (funcall f window oldpos 'left)))
- (dolist (f new)
- (unless (and (memq f (cdr old)) (not (funcall missing-p f)))
- (funcall f window oldpos 'entered)))))
-
- ;; Remember current state for next time.
- ;; Re-read cursor-sensor-functions since the functions may have moved
- ;; window-point!
- (if old
- (progn (move-marker (car old) point)
- (setcdr old new))
- (set-window-parameter window 'cursor-sensor--last-state
- (cons (copy-marker point) new))))))
+ (with-current-buffer (window-buffer window)
+ (unless cursor-sensor-inhibit
+ (let* ((point (window-point window))
+ ;; It's often desirable to make the
+ ;; cursor-sensor-functions property non-sticky on both
+ ;; ends, but that means get-pos-property might never
+ ;; see it.
+ (new (or (get-char-property point 'cursor-sensor-functions)
+ (unless (<= (point-min) point)
+ (get-char-property (1- point)
+ 'cursor-sensor-functions))))
+ (old (window-parameter window 'cursor-sensor--last-state))
+ (oldposmark (car old))
+ (oldpos (or (if oldposmark (marker-position oldposmark))
+ (point-min)))
+ (start (min oldpos point))
+ (end (max oldpos point)))
+ (unless (or (null old) (eq (marker-buffer oldposmark) (current-buffer)))
+ ;; `window' does not display the same buffer any more!
+ (setcdr old nil))
+ (if (or (and (null new) (null (cdr old)))
+ (and (eq new (cdr old))
+ (eq (next-single-char-property-change
+ start 'cursor-sensor-functions nil end)
+ end)))
+ ;; Clearly nothing to do.
+ nil
+ ;; Maybe something to do. Let's see exactly what needs to run.
+ (let* ((missing-p
+ (lambda (f)
+ "Non-nil if F is missing somewhere between START and END."
+ (let ((pos start)
+ (missing nil))
+ (while (< pos end)
+ (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)))
+ (window (selected-window)))
+ (dolist (f (cdr old))
+ (unless (and (memq f new) (not (funcall missing-p f)))
+ (funcall f window oldpos 'left)))
+ (dolist (f new)
+ (unless (and (memq f (cdr old)) (not (funcall missing-p f)))
+ (funcall f window oldpos 'entered)))))
+
+ ;; Remember current state for next time.
+ ;; Re-read cursor-sensor-functions since the functions may have moved
+ ;; window-point!
+ (if old
+ (progn (move-marker (car old) point)
+ (setcdr old new))
+ (set-window-parameter window 'cursor-sensor--last-state
+ (cons (copy-marker point) new)))))))
;;;###autoload
(define-minor-mode cursor-sensor-mode