emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 b916ec88b2f: Make eglot-ensure's post-command-hook run a bit la


From: João Távora
Subject: emacs-29 b916ec88b2f: Make eglot-ensure's post-command-hook run a bit later (bug#62065)
Date: Sun, 12 Mar 2023 14:50:08 -0400 (EDT)

branch: emacs-29
commit b916ec88b2ffe22a49128f17cdfb78f0ab1bc713
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Make eglot-ensure's post-command-hook run a bit later (bug#62065)
    
    'eglot-ensure', typically used in the major-mode-hook, use
    'post-command-hook' to schedule an automated, non-interactive
    connection attempt to a server.  The goal is to connect when the
    buffer is ready, i.e. after the user command that found the file.
    
    However, if there are dir-local or buffer-local variables to confirm,
    finding the file will cause a minibuffer prompt to appear.
    
    In that case, 'eglot-ensure's addition to the global post-command-hook
    runs before it was intended too and a connection is started
    prematurely.
    
    In turn, this means that a call to 'hack-dir-local-variables' -- which
    is part of the connection process -- which also needs a minibuffer
    prompt, collides with the previous one.  This generates an error and
    confuses the user, who doesn't know if the directory-local variables
    have been applied or not.
    
    This commit fixes the clash by having 'eglot-ensure' set
    'post-command-hook' buffer-locally.  This causes the automated
    connection to take place, as intended, after the user's original
    file-finding command has ended.
    
    However, the problem reported in bug#62065 is not completely fixed.
    If the user answers "no" to the first "confirm local variables"
    "prompt, she will be prompted again in the second one.  A subsequent
    commit will address this separate problem.
    
    * lisp/progmodes/eglot.el (eglot-ensure): Use buffer-local 
post-command-hook.
---
 lisp/progmodes/eglot.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 2679773c117..758be488680 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1155,12 +1155,13 @@ INTERACTIVE is t if called interactively."
     (cl-labels
         ((maybe-connect
            ()
-           (remove-hook 'post-command-hook #'maybe-connect nil)
            (eglot--when-live-buffer buffer
+             (remove-hook 'post-command-hook #'maybe-connect t)
              (unless eglot--managed-mode
                (apply #'eglot--connect (eglot--guess-contact))))))
-      (when buffer-file-name
-        (add-hook 'post-command-hook #'maybe-connect 'append nil)))))
+      (when (and this-command
+                 buffer-file-name)
+        (add-hook 'post-command-hook #'maybe-connect 'append t)))))
 
 (defun eglot-events-buffer (server)
   "Display events buffer for SERVER.



reply via email to

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