Subject: Re: bug#62065: 30.0.50; No prompt to confirm unsafe local variables when eglot-ensure used in major mode hook

From: João Távora <[email-masked]>
Date: Sat, 11 Mar 2023 15:01:58 +0000

João Távora <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
> No, not yet.  I haven't tried to reproduce it yet, nor do I understand
> what is going on.

I've now reproduced the problem, but Emacs is not silent about it, I see
an error in *Messages*

   Directory-local variables error: (error Command attempted to use minibuffer while in minibuffer)

> But the main question to ask is: is the '(setq foo 42)' getting
> evaluated without the user's consent?

I've confirmed it does _not_.

Matt can you confirm this as well (both the error and the non-setting)?

Anyway, this is the implementation of 'eglot-ensure'.  It's pretty
simple.  The idea is to wait until the very last moment to do the
connection, hence the user of post-command-hook.  Maybe some assumption
here is wrong.  I will debug later.

(defun eglot-ensure ()
  "Start Eglot session for current buffer if there isn't one."
  (let ((buffer (current-buffer)))
    (cl-labels
        ((maybe-connect
           ()
           (remove-hook 'post-command-hook #'maybe-connect nil)
           (eglot--when-live-buffer buffer
             (unless eglot--managed-mode
               (apply #'eglot--connect (eglot--guess-contact))))))
      (when buffer-file-name
        (add-hook 'post-command-hook #'maybe-connect 'append nil)))))

João