]> git.eshelyaron.com Git - emacs.git/commitdiff
Unbreak m-x vc-revert, which reverts preserving modes
authorJoão Távora <joaotavora@gmail.com>
Mon, 21 Oct 2019 15:07:38 +0000 (16:07 +0100)
committerJoão Távora <joaotavora@gmail.com>
Mon, 21 Oct 2019 15:07:38 +0000 (16:07 +0100)
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.

lisp/progmodes/eglot.el

index e1c7b48c8d69683394f70decc2b0ac4dea73694c..bd5f1ac8d4c985f05a2d356449bc6d8bc0cc2e50 100644 (file)
@@ -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