eglot icon indicating copy to clipboard operation
eglot copied to clipboard

Is it possible to turn on eglot--managed-mode only when the buffer is selected by user?

Open netjune opened this issue 6 years ago • 10 comments

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?

netjune avatar Feb 02 '19 07:02 netjune

No, but this is a good idea. Flymake does this, I can just copy the code.

joaotavora avatar Feb 02 '19 10:02 joaotavora

@netjune, how do you end up with that 200 buffers?

  • If you use desktop-save-mode, then customizing desktop-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 avatar Jan 22 '20 18:01 nemethf

@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.

joaotavora avatar Jan 22 '20 18:01 joaotavora

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.

nemethf avatar Jan 22 '20 19:01 nemethf

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.

joaotavora avatar Jan 22 '20 19:01 joaotavora

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.

joaotavora avatar Jan 22 '20 19:01 joaotavora

@netjune, how do you end up with that 200 buffers?

  • If you use desktop-save-mode, then customizing desktop-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:

  1. my-session-new: save and unload the current session and then create a new empty one
  2. 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.

netjune avatar Jan 23 '20 03:01 netjune

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.

netjune avatar Jan 23 '20 03:01 netjune

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.

nemethf avatar Jan 23 '20 17:01 nemethf

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.

joaotavora avatar Jan 23 '20 17:01 joaotavora