From 7652fd090993f523fcf249fa8f2ed70ccfe784b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sun, 27 May 2018 16:51:15 +0100 Subject: [PATCH] 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. --- lisp/progmodes/eglot.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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." -- 2.39.2