bug#81593: [PATCH] Respect eglot-stay-out-of when disabling eglot--managed-mode

Aaron Zeng via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <CAB7SQMEwMUx3oq2i_=POn8q3G5EvoZjqZUBj6uCRXF4gBHUXyg@mail.gmail.com>
On Tue, Aug 11, 2026 at 8:25 AM João Távora <[email protected]> wrote:
>
> I think this makes sense. If you format the subject line to be slightly shorter and start with "Eglot: " like the other Eglot commits and add the bug ref, I think someone else can push it (and that someone can make the edits themselves if they want).
>
> Maybe
>
> Eglot: respect e-stay-out-of when turning off (bug#81593)

Thanks for reviewing.  I ended up going with this suggestion verbatim.
New patch attached.
0001-Eglot-respect-e-stay-out-of-when-turning-off-bug-815.patch (text/x-patch, 2.5 KB)
From 53f436eff9806f7ac5a8bea880c12b15d5dc9dfe Mon Sep 17 00:00:00 2001
From: "Aaron L. Zeng" <[email protected]>
Date: Mon, 10 Aug 2026 17:43:21 -0400
Subject: [PATCH] Eglot: respect e-stay-out-of when turning off (bug#81593)

* lisp/progmodes/eglot.el (eglot--managed-mode): Respect
`eglot-stay-out-of' during teardown/reconnect.
---
 lisp/progmodes/eglot.el | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 1c9569434cf..ee36b66a8b6 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2477,21 +2477,24 @@ eglot--managed-mode
                  #'eglot--after-set-visited-file-name-hook t)
     (remove-hook 'before-save-hook #'eglot--signal-textDocument/willSave t)
     (remove-hook 'after-save-hook #'eglot--signal-textDocument/didSave t)
-    (remove-hook 'xref-backend-functions #'eglot-xref-backend t)
+    (unless (eglot--stay-out-of-p 'xref)
+      (remove-hook 'xref-backend-functions #'eglot-xref-backend t))
     (remove-hook 'completion-at-point-functions #'eglot-completion-at-point t)
     (remove-hook 'completion-in-region-mode-hook #'eglot--capf-session-flush t)
     (remove-hook 'company-after-completion-hook #'eglot--capf-session-flush t)
     (remove-hook 'change-major-mode-hook #'eglot--managed-mode-off t)
     (remove-hook 'post-self-insert-hook #'eglot--post-self-insert-hook t)
     (remove-hook 'pre-command-hook #'eglot--pre-command-hook t)
-    (dolist (f (list #'eglot-hover-eldoc-function
-                     #'eglot-signature-eldoc-function
-                     #'eglot-highlight-eldoc-function
-                     #'eglot-code-action-suggestion))
-        (remove-hook 'eldoc-documentation-functions f t))
+    (unless (eglot--stay-out-of-p 'eldoc)
+      (dolist (f (list #'eglot-hover-eldoc-function
+                       #'eglot-signature-eldoc-function
+                       #'eglot-highlight-eldoc-function
+                       #'eglot-code-action-suggestion))
+        (remove-hook 'eldoc-documentation-functions f t)))
     (cl-loop for (var . saved-binding) in eglot--saved-bindings
              do (set (make-local-variable var) saved-binding))
-    (remove-function (local 'imenu-create-index-function) #'eglot-imenu)
+    (unless (eglot--stay-out-of-p 'imenu)
+      (remove-function (local 'imenu-create-index-function) #'eglot-imenu))
     (eglot--flymake-reset)
     (setq eglot--flymake-report-fn nil)
     (run-hooks 'eglot-managed-mode-hook)
-- 
2.43.7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.