emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot af9dcad 10/22: Take over Flymake and Eldoc comple


From: João Távora
Subject: [elpa] externals/eglot af9dcad 10/22: Take over Flymake and Eldoc completely while managing buffers
Date: Sat, 5 Jan 2019 09:31:03 -0500 (EST)

branch: externals/eglot
commit af9dcad2e677fa7eb59faa39561f3c60f4e886d7
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Take over Flymake and Eldoc completely while managing buffers
    
    Take a pragmatic approach and override all other Flymake and Eglot
    backends while Eglot is enabled.  Restore previous values after
    eglot-shutdown.
    
    Certainly cases might arise where using more than one datasource
    besides LSP while Eglot is managing the buffer is useful.  But
    currently contrary, it confuses users enabling Eglot in buffers that
    already have flymake/eldoc backends configured.
    
    The reasons are slightly different for Eldoc and Flymake:
    
    - For Eldoc the :before-until strategy only makes sense for
      synchronous backends, which Eglot isn't.  This conflicts with
      python.el default python-eldoc-function, which is also asynchronous.
    
    - For Flymake, the default backends in Emacs (python-mode, c-mode, and
      a few others) are mainly repetitions of what LSP does.  The global
      value is still run though (in case you want to put, say, a
      spell-checking backend there).
    
    * eglot.el (eglot--saved-bindings, eglot--setq-saving): New
    helpers.
    (eglot--managed-mode): Use them.
---
 eglot.el | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/eglot.el b/eglot.el
index 60dad45..7f3eea4 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1118,6 +1118,14 @@ and just return it.  PROMPT shouldn't end with a 
question mark."
 (defvar-local eglot--current-flymake-report-fn nil
   "Current flymake report function for this buffer")
 
+(defvar-local eglot--saved-bindings nil
+  "Bindings saved by `eglot--setq-saving'.")
+
+(defmacro eglot--setq-saving (symbol binding)
+  `(progn (push (cons ',symbol (symbol-value ',symbol))
+                eglot--saved-bindings)
+          (setq-local ,symbol ,binding)))
+
 (define-minor-mode eglot--managed-mode
   "Mode for source buffers managed by some EGLOT project."
   nil nil eglot-mode-map
@@ -1125,7 +1133,6 @@ and just return it.  PROMPT shouldn't end with a question 
mark."
    (eglot--managed-mode
     (add-hook 'after-change-functions 'eglot--after-change nil t)
     (add-hook 'before-change-functions 'eglot--before-change nil t)
-    (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)
     (add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose nil t)
     (add-hook 'kill-buffer-hook 'eglot--managed-mode-onoff nil t)
     (add-hook 'before-revert-hook 'eglot--signal-textDocument/didClose nil t)
@@ -1136,8 +1143,8 @@ and just return it.  PROMPT shouldn't end with a question 
mark."
     (add-hook 'change-major-mode-hook 'eglot--managed-mode-onoff nil t)
     (add-hook 'post-self-insert-hook 'eglot--post-self-insert-hook nil t)
     (add-hook 'pre-command-hook 'eglot--pre-command-hook nil t)
-    (add-function :before-until (local 'eldoc-documentation-function)
-                  #'eglot-eldoc-function)
+    (eglot--setq-saving eldoc-documentation-function #'eglot-eldoc-function)
+    (eglot--setq-saving flymake-diagnostic-functions '(eglot-flymake-backend 
t))
     (add-function :around (local 'imenu-create-index-function) #'eglot-imenu)
     (flymake-mode 1)
     (eldoc-mode 1))
@@ -1154,9 +1161,8 @@ and just return it.  PROMPT shouldn't end with a question 
mark."
     (remove-hook 'change-major-mode-hook #'eglot--managed-mode-onoff t)
     (remove-hook 'post-self-insert-hook 'eglot--post-self-insert-hook t)
     (remove-hook 'pre-command-hook 'eglot--pre-command-hook t)
-    (remove-function (local 'eldoc-documentation-function)
-                     #'eglot-eldoc-function)
-    (remove-function (local 'imenu-create-index-function) #'eglot-imenu)
+    (cl-loop for (var . saved-binding) in eglot--saved-bindings
+             do (set (make-local-variable var) saved-binding))
     (setq eglot--current-flymake-report-fn nil))))
 
 (defvar-local eglot--cached-current-server nil



reply via email to

[Prev in Thread] Current Thread [Next in Thread]