From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#70958: 30.0.50; eglot-managed-mode hooks not called on shutdown Date: Sun, 26 May 2024 23:46:38 +0100 Message-ID: References: <86y17yz5sr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25845"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70958@debbugs.gnu.org, Troy Brown To: Eli Zaretskii , Felician Nemeth , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 27 00:49:10 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sBMfu-0006Wd-1T for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 May 2024 00:49:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBMfe-00052j-TC; Sun, 26 May 2024 18:48:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBMfe-00052a-1K for bug-gnu-emacs@gnu.org; Sun, 26 May 2024 18:48:54 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBMfd-000829-Pp for bug-gnu-emacs@gnu.org; Sun, 26 May 2024 18:48:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sBMfm-0001oB-3d for bug-gnu-emacs@gnu.org; Sun, 26 May 2024 18:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 May 2024 22:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70958 X-GNU-PR-Package: emacs Original-Received: via spool by 70958-submit@debbugs.gnu.org id=B70958.17167636876862 (code B ref 70958); Sun, 26 May 2024 22:49:02 +0000 Original-Received: (at 70958) by debbugs.gnu.org; 26 May 2024 22:48:07 +0000 Original-Received: from localhost ([127.0.0.1]:42691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBMes-0001mc-Pz for submit@debbugs.gnu.org; Sun, 26 May 2024 18:48:07 -0400 Original-Received: from mail-lf1-f42.google.com ([209.85.167.42]:60464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBMeq-0001m7-Me for 70958@debbugs.gnu.org; Sun, 26 May 2024 18:48:05 -0400 Original-Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-529aa4e988aso1231036e87.0 for <70958@debbugs.gnu.org>; Sun, 26 May 2024 15:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716763610; x=1717368410; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=B1Oa+TDyzz292AUdOB71qmBysubYLpRj5wD92Saf6Eo=; b=C45rzehaY7MVS5P1uwY013QqgbDgYZlxmqtnoxp/GTD7rlGWRGMZVEQnMUuq8L0Npb IuDf208l7Agb//NC2fEkKrSskxUmLM3ICf9t1VylsCGNeYI4Yys5nR47A0+TCNVq31AT w5LyczGk1EcGyyU2iC0oMFpQ7MFRh9+5utuxwDJgRYbbrL/DzawC3+ELTFTao53CpPRZ WTIAou7kw5/jIwkSuPujyAb0O8+/g0fkCgW68JRQrE8cimG8PAKeA5gboSq+RR0qW1RL NqwbcTP94BdR4UWHi5kT9Juad6BHZk5+d1aI05CiCNvVwvb6mxSmRnKAGVngLRGLwvGw 6szw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716763610; x=1717368410; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B1Oa+TDyzz292AUdOB71qmBysubYLpRj5wD92Saf6Eo=; b=hWxRE9Vuy0hoVym6fuAXzpAVYzYx1l8RjbpshtnTIPYBhjMR7/B6cOU4PMhWG2Wr8E AQgsgN5otYQm3zarNPsRhEsBMTwHwZTQN/GYk48s3hYml98D5gKKrDNZ1lTPo9S4cPXG zn1hoy5vRlI/ZpUqNc1awUlBFj2AMYM5Pnu0p/RKTMerjMkbop7E+OmC2zxvtvb+XF5O iZ5Zb764a65iSxl1j5JW43SutorpqKyNI8ZiBgY2AdCq5Im6AJXjlcP5VbhSpWvyNMSy p0VFRdIGXlpHlTQNoXE1vUnxTB8DKrM0LHt75yZvz/43K3kmvvQzvPHi+OcM6oIb3I+S hTfw== X-Forwarded-Encrypted: i=1; AJvYcCUlo0dwVP59Hf0pyUXimIUBw0fHO7RipZR4Rg5gbWMaN2c7ZsKXip0THq+uwoqyG4abKMC9q+p/B2Kz4vSRElTXbxCcEls= X-Gm-Message-State: AOJu0YzjGur9aryBmLmAqr6ari1A+38yOHCQaXQHPvzK1hQkkOMUhtH/ ahFZskrULkEbF4WZ7kilkPZ9w0F2ZfiU6E6v/CaQuTLWSS1LtDs02r/IlfGafV0MrD8i9f8BQqO 52GIwkvrmQQkMPL/3kustq7Cyshs= X-Google-Smtp-Source: AGHT+IHztpK/YbDFcoa0iJemDeZYrcA086jBzW8dusXQ8Xae87fclj/q1CQy499Mlb3wBpyfFPNvinK5ZWcZqj/544c= X-Received: by 2002:a19:7705:0:b0:523:bb4c:7b99 with SMTP id 2adb3069b0e04-5296420821fmr4758667e87.8.1716763609909; Sun, 26 May 2024 15:46:49 -0700 (PDT) In-Reply-To: <86y17yz5sr.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286001 Archived-At: On Sat, May 25, 2024 at 8:53=E2=80=AFAM Eli Zaretskii wrote: > > > From: Troy Brown > > 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=C3=A3o, 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=C3=A1n and Stefan for suggestions. Jo=C3=A3o