summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2024-05-04 17:14:46 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2024-05-04 17:14:46 -0400
commit043bb36312039f60a464b918daa1dd214cd369f1 (patch)
tree6f4a668f59c5b50549c3c119bb471911499a874c
parent672ca232db0a30e45b7f3f5e06b8fc6f12e23faa (diff)
downloademacs-043bb36312039f60a464b918daa1dd214cd369f1.tar.gz
(eglot--track-changes-signal): Improve last fix (bug#70541)
* lisp/progmodes/eglot.el (eglot--add-one-shot-hook): New function. (eglot--track-changes-signal): Use it.
-rw-r--r--lisp/progmodes/eglot.el25
1 files changed, 16 insertions, 9 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 8ba47fe268d..47d45a100f2 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2679,6 +2679,15 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
,(buffer-substring-no-properties beg end))
eglot--recent-changes))))))
+(defun eglot--add-one-shot-hook (hook function &optional append local)
+ "Like `add-hook' but calls FUNCTION only once."
+ (let* ((fname (make-symbol (format "eglot--%s-once" function)))
+ (fun (lambda (&rest args)
+ (remove-hook hook fname local)
+ (apply function args))))
+ (fset fname fun)
+ (add-hook hook fname append local)))
+
(defun eglot--track-changes-signal (id &optional distance)
(cond
(distance
@@ -2697,15 +2706,13 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
(when eglot--managed-mode
(if (and (fboundp 'track-changes-inconsistent-state-p)
(track-changes-inconsistent-state-p))
- ;; Not a good time (e.g. in the middle of Quail
- ;; thingy, bug#70541), let's reschedule.
- ;; Ideally, we'd `run-with-idle-timer' to call
- ;; ourselves again but it's kind of a pain to do that
- ;; right (because we first have to wait for the
- ;; current idle period to end), so we just do
- ;; nothing and wait for the next buffer change to
- ;; reschedule us.
- nil
+ ;; Not a good time (e.g. in the middle of Quail thingy,
+ ;; bug#70541): reschedule for the next idle period.
+ (eglot--add-one-shot-hook
+ 'post-command-hook
+ (lambda ()
+ (eglot--when-live-buffer buf
+ (eglot--track-changes-signal id))))
(run-hooks 'eglot--document-changed-hook)
(setq eglot--change-idle-timer nil)))))
(current-buffer))))