From: João Távora Date: Mon, 21 Oct 2019 15:07:38 +0000 (+0100) Subject: Unbreak m-x vc-revert, which reverts preserving modes X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~291 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0816da8e78f1d0d643fdd1259a2f307c0817e316;p=emacs.git Unbreak m-x vc-revert, which reverts preserving modes Unlike the normal revert-buffer command, vc-revert, doesn't re-apply the major mode, meaning it was missing a didOpen to pair with the didClose that is unconditionally sent on both commands. Needed to use the dynamic variable revert-buffer-preserve-modes, and, curiously, also forward-declare it to appease the byte compiler. * eglot.el (eglot--managed-mode): Use after-revert-hook. (revert-buffer-preserve-modes): Forward declare. (eglot--after-revert-hook): Signal didOpen when preserving-modes. (eglot--maybe-activate-editing-mode): Tweak comment. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index e1c7b48c8d6..bd5f1ac8d4c 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1214,6 +1214,7 @@ For example, to keep your Company customization use ;; Prepend "didClose" to the hook after the "onoff", so it will run first (add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose nil t) (add-hook 'before-revert-hook 'eglot--signal-textDocument/didClose nil t) + (add-hook 'after-revert-hook 'eglot--after-revert-hook nil t) (add-hook 'before-save-hook 'eglot--signal-textDocument/willSave nil t) (add-hook 'after-save-hook 'eglot--signal-textDocument/didSave nil t) (add-hook 'xref-backend-functions 'eglot-xref-backend nil t) @@ -1233,6 +1234,7 @@ For example, to keep your Company customization use (remove-hook 'before-change-functions 'eglot--before-change t) (remove-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose t) (remove-hook 'before-revert-hook 'eglot--signal-textDocument/didClose t) + (remove-hook 'after-revert-hook 'eglot--after-revert-hook t) (remove-hook 'before-save-hook 'eglot--signal-textDocument/willSave t) (remove-hook 'after-save-hook 'eglot--signal-textDocument/didSave t) (remove-hook 'xref-backend-functions 'eglot-xref-backend t) @@ -1286,6 +1288,11 @@ Reset in `eglot--managed-mode-onoff'.") (defvar-local eglot--unreported-diagnostics nil "Unreported Flymake diagnostics for this buffer.") +(defvar revert-buffer-preserve-modes) +(defun eglot--after-revert-hook () + "Eglot's `after-revert-hook'." + (when revert-buffer-preserve-modes (eglot--signal-textDocument/didOpen))) + (defun eglot--maybe-activate-editing-mode (&optional server) "Maybe activate mode function `eglot--managed-mode'. If SERVER is supplied, do it only if BUFFER is managed by it. In @@ -1297,7 +1304,8 @@ that case, also signal textDocument/didOpen." :eglot "`eglot--cached-current-server' is non-nil, but it shouldn't be!\n\ Please report this as a possible bug.") (setq eglot--cached-current-server nil))) - ;; Called even when revert-buffer-in-progress-p + ;; Called when `revert-buffer-in-progress-p' is t but + ;; `revert-buffer-preserve-modes' is nil. (let* ((cur (and buffer-file-name (eglot--current-server))) (server (or (and (null server) cur) (and server (eq server cur) cur)))) (when server