eglot
eglot copied to clipboard
Is it possible to turn on eglot--managed-mode only when the buffer is selected by user?
When I run eglot, it turn on eglot--managed-mode for all opened buffers. It takes too long time because there are more than 200 buffers.
Is it possible to turn on eglot--managed-mode only when the buffer is selected by user?
No, but this is a good idea. Flymake does this, I can just copy the code.
@netjune, how do you end up with that 200 buffers?
- If you use
desktop-save-mode
, then customizingdesktop-restore-eager
might be the solution. - If you opened the files first and enabled Eglot later, try to enable Eglot when a file is just opened with
eglot-ensure
- If you opened the files with something like
C-x C-f *.py
, then that's not a good practice to open that many files. - If none of the above, then how?
Also it might be tricky to correctly implement the "turning on eglot--managed-mode only when the buffer is selected by user" feature, because the server would think it is its responsibility to manage the file if the client does not claim responsibility. So when the user finally selects a hidden buffer, that buffer might be out of sync. Caveat: I don't know this part of the specification well (or at all.)
@nemethf it's tricky to implement, but not impossible. As I said, look in the flymake code. I think flycheck does the same trick.
There might be many reasons why people have 200 buffers open (I don't even want to look how many I have right now), so let's not go into that.
because the server would think it is its responsibility to manage the file if the client does not claim responsibility.
But that's what LSP does, right? Give management of the file to the server. @netjune just wants to delay the awareness that Emacs has of that delegation when it's needed.
There might be many reasons why people have 200 buffers open (I don't even want to look how many I have right now), so let's not go into that.
It's OK to have many files open. It's strange that someone wants to enable Eglot for all them at the same time.
It's strange that someone wants to enable Eglot for all them at the same time.
But one doesn't enable Eglot for a file, one enables it for a project. I think @netjune is requesting that once he does that, he doesn't overload his server with a million didOpen
notifications all at once.
FTR I think @netjune's description is slightly off. I.e. I don't think enabling the mode is really the culprit here, rather the ensuing communication with the LSP server. But it doesn't change much in practice.
@netjune, how do you end up with that 200 buffers?
- If you use
desktop-save-mode
, then customizingdesktop-restore-eager
might be the solution.- If you opened the files first and enabled Eglot later, try to enable Eglot when a file is just opened with
eglot-ensure
- If you opened the files with something like
C-x C-f *.py
, then that's not a good practice to open that many files.- If none of the above, then how?
Also it might be tricky to correctly implement the "turning on eglot--managed-mode only when the buffer is selected by user" feature, because the server would think it is its responsibility to manage the file if the client does not claim responsibility. So when the user finally selects a hidden buffer, that buffer might be out of sync. Caveat: I don't know this part of the specification well (or at all.)
I don't use desktop.el derectly. I wrote a package to manager my desktop sessions. It is based on desktop.el. It provides the following commands:
- my-session-new: save and unload the current session and then create a new empty one
- my-session-load: save and unload the current session and then load another
And I switch sessions using my-session-load many times everyday. After every switching, I edit only a few of the files(maybe 10 of the 200) in the session. It is a waste of time to turn on eglot for every buffer.
Current I have defined a function my-eglot-try-to-enable and setup a timer to run it repeatedly every 1 second. It checks and try to turn on eglot for the current buffer. It works well.
But I'm using lsp-mode now.
At any rate, I've found a scenario where the flood of DidOpen messages happens and I consider important: restarting a running server with M-x eglot RET n
.
Yep, this is something to fix regardless of @netjune 's desertion ahahaha .
Importantly, the way to fix it is not that timer every one second. See flymake.el
's code for a technique involving window-configuration-change-hook
in flymake-start
. Or check flycheck's code, if you prefer, but I can explain the workings of the flymake function better, because I wrote it.