From: "João Távora" <joaotavora@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>,
Felician Nemeth <felician.nemeth@gmail.com>,
Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 70958@debbugs.gnu.org, Troy Brown <brownts@troybrown.dev>
Subject: bug#70958: 30.0.50; eglot-managed-mode hooks not called on shutdown
Date: Sun, 26 May 2024 23:46:38 +0100 [thread overview]
Message-ID: <CALDnm52bQJGKe-Bv8DzJTqpjf5LxVOPSmQzGRqc_Gx2kU1g0QQ@mail.gmail.com> (raw)
In-Reply-To: <86y17yz5sr.fsf@gnu.org>
On Sat, May 25, 2024 at 8:53 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Troy Brown <brownts@troybrown.dev>
> > Date: Wed, 15 May 2024 08:38:28 -0400
> >
> > The documentation for eglot-managed-mode-hook indicates that the hook
> > is run after Eglot has started/stopped managing a buffer. I was
> > trying to use this to perform setup/teardown of functionality when
> > this happened, but it appears the registered hooks are never called on
> > shutdown. The following is a little test that can be run in a buffer
> > which has LSP support, to demonstrate the problem. My expectation is
> > that "Buffer not managed" is output and the my-eglot-hook-var is
> > changed to 'not-managed when a shutdown occurs.
> >
> > --8<---------------cut here---------------start------------->8---
> > (defun my-eglot-test ()
> > (defun my-eglot-hook ()
> > (message "my-eglot-hook invoked")
> > (if (eglot-managed-p)
> > (progn
> > (message "Buffer is managed")
> > (setq-local my-eglot-hook-var 'managed))
> > (message "Buffer not managed")
> > (setq-local my-eglot-hook-var 'not-managed)))
> > (add-hook 'eglot-managed-mode-hook #'my-eglot-hook)
> > (setq-local my-eglot-hook-var 'initial)
> > (cl-assert (not (eglot-managed-p)))
> > (cl-assert (eq my-eglot-hook-var 'initial))
> > (call-interactively #'eglot)
> > (cl-assert (eglot-managed-p))
> > (cl-assert (eq my-eglot-hook-var 'managed))
> > (sleep-for 3) ; wait for server connection
> > (call-interactively #'eglot-shutdown)
> > (cl-assert (not (eglot-managed-p)))
> > (cl-assert (eq my-eglot-hook-var 'not-managed)))
> > --8<---------------cut here---------------end--------------->8---
>
> João, any comments or suggestions?
eglot-managed-mode-hook is an abnormal minor mode hook because there
is no eglot-managed-mode minor mode, there is only eglot--managed-mode
which is a "--" definition on purpose (that does have the normal hooks
of course).
So when e-m-m-hook was added it was made to run only on "turn on"
because that's where it was most needed. We can try changing Eglot
to also run it on "turn off", but that is a backward incompatible
change.
Alternatively, we can add a new eglot-managed-mode-off-hook.
Whatever the decision, there is the additional question of _when_ to
run the "off". Maybe it's simple to decide, but at least the the
"on" e-m -m-hook is specially designed to run after some
LSP communication has taken place, which is of the reasons
eglot--managed-mode-hook wasn't suitable. So maybe the "off"
should run in a similarly careful symmetrical position.
Finally, Troy can probably also make use of the internal
eglot--managed-mode-hook. It's a "--", unsupported and dangerous
in theory, in practice it should be OK.
I'm CCing Felicián and Stefan for suggestions.
João
next prev parent reply other threads:[~2024-05-26 22:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 12:38 bug#70958: 30.0.50; eglot-managed-mode hooks not called on shutdown Troy Brown
2024-05-25 7:53 ` Eli Zaretskii
2024-05-26 22:46 ` João Távora [this message]
2024-05-27 12:29 ` Troy Brown
2024-05-27 12:35 ` João Távora
2024-05-27 12:45 ` Troy Brown
2024-05-27 14:09 ` João Távora
2024-05-27 14:32 ` Troy Brown
2024-05-27 15:45 ` João Távora
2024-05-27 15:51 ` João Távora
2024-05-27 16:21 ` Felician Nemeth
2024-05-27 17:22 ` João Távora
2024-05-27 17:35 ` Felician Nemeth
2024-05-27 21:05 ` João Távora
2024-05-27 22:21 ` João Távora
2024-05-28 13:00 ` Troy Brown
2024-06-01 14:18 ` Eli Zaretskii
[not found] ` <CALDnm507yRL6y6VcM-OwHUhSmFbpcFhsUb00wabirPkfq7ZAow@mail.gmail.com>
2024-06-01 16:01 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALDnm52bQJGKe-Bv8DzJTqpjf5LxVOPSmQzGRqc_Gx2kU1g0QQ@mail.gmail.com \
--to=joaotavora@gmail.com \
--cc=70958@debbugs.gnu.org \
--cc=brownts@troybrown.dev \
--cc=eliz@gnu.org \
--cc=felician.nemeth@gmail.com \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.