From: João Távora Date: Sun, 27 May 2018 15:51:15 +0000 (+0100) Subject: Be more criterious before running the idle timer X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~528 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7652fd090993f523fcf249fa8f2ed70ccfe784b7;p=emacs.git Be more criterious before running the idle timer * eglot.el (eglot--change-idle-timer): make a defvar-local (eglot--after-change): Only run timer if the buffer is live. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index c48aa2bf83f..8ab4b496e2d 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1118,7 +1118,7 @@ THINGS are either registrations or unregisterations." (defmethod eglot-server-ready-p (_s _what) "Normally ready if no outstanding changes." (not eglot--recent-changes)) -(defvar eglot--change-idle-timer nil "Idle timer for textDocument/didChange.") +(defvar-local eglot--change-idle-timer nil "Idle timer for didChange signals.") (defun eglot--before-change (start end) "Hook onto `before-change-functions'. @@ -1141,10 +1141,14 @@ Records START, END and PRE-CHANGE-LENGTH locally." `(,pre-change-length ,(buffer-substring-no-properties start end))) (setf eglot--recent-changes :emacs-messup)) (when eglot--change-idle-timer (cancel-timer eglot--change-idle-timer)) - (setq eglot--change-idle-timer - (run-with-idle-timer - 0.5 nil (lambda () (eglot--signal-textDocument/didChange) - (setq eglot--change-idle-timer nil))))) + (let ((buf (current-buffer))) + (setq eglot--change-idle-timer + (run-with-idle-timer + 0.5 nil (lambda () (when (buffer-live-p buf) + (with-current-buffer buf + (when eglot--managed-mode + (eglot--signal-textDocument/didChange) + (setq eglot--change-idle-timer nil))))))))) (defun eglot--signal-textDocument/didChange () "Send textDocument/didChange to server."