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: Mon, 27 May 2024 16:51:17 +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="14196"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70958@debbugs.gnu.org, Eli Zaretskii , Felician Nemeth , Stefan Monnier To: Troy Brown Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 27 17:53: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 1sBcer-0003TU-R8 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 May 2024 17:53:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBced-00047M-4R; Mon, 27 May 2024 11:52:55 -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 1sBceb-00046z-SO for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 11:52:53 -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 1sBceb-0006RH-Jn for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 11:52:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sBcek-0002cI-3T for bug-gnu-emacs@gnu.org; Mon, 27 May 2024 11:53: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: Mon, 27 May 2024 15:53: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.171682516710032 (code B ref 70958); Mon, 27 May 2024 15:53:02 +0000 Original-Received: (at 70958) by debbugs.gnu.org; 27 May 2024 15:52:47 +0000 Original-Received: from localhost ([127.0.0.1]:45095 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBceU-0002bj-F2 for submit@debbugs.gnu.org; Mon, 27 May 2024 11:52:46 -0400 Original-Received: from mail-lf1-f54.google.com ([209.85.167.54]:51551) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBceS-0002bW-20 for 70958@debbugs.gnu.org; Mon, 27 May 2024 11:52:44 -0400 Original-Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5296935252dso3195987e87.3 for <70958@debbugs.gnu.org>; Mon, 27 May 2024 08:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716825089; x=1717429889; 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=X9egqEh/ntPXjBCIyYFxWWe719mfuRP5QstTmJ15P5c=; b=cU4f4p5iOAmNNL3wsLXS1tRB+Nhny89X8OXORhjGd2kBUrXWTVRPImRXIeZepJNuac DiVgLXmbAMC4oLANmaugr1nk7Fvj+8CKoPxufG2Yf+Jz+sahdoWGa6xzH7JB8iPO1uWk eKDymBr9sc+m7soFWkbcckTPoxG2OW0EQM7HPAjmiEh7gi3+ySf25TJkV3wCX5LzZecZ gZGF8vIroq9dmD1gFBCZUuOcSbTtypsII5zv2z/81SvH4TwvEOAIGG/Fb8SDb/gpUY5S hh4oolJ4pu70uuswrokE5WFKfTlgQXfN1I2CJgWg8z0nVkEEWeRaCxpGGmtRkMxc83V0 bLxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716825089; x=1717429889; 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=X9egqEh/ntPXjBCIyYFxWWe719mfuRP5QstTmJ15P5c=; b=Jz1Qbd3DyHxcztlJatFNjPx0HihSggBmLHw66SvXOfOPzyAVxtQvh7s/6Y1pURGHO1 M6i5xQPaBIq6drzLhGK2VAUNO6b1YRHaBpwRdhIwpJlBFiuDoCmggRqAsp8KEwBy/9QT ZCD4jByCsG6TXl8fuFdIDwPGr9NpDQ76DIgkubgHA4ZZ4Fha/K8/aUS9zxOLtE6sYIzE 9Qi3MimrZDfqWgDtU8+IlYgAl2YV4z052uqIYIWX/6QIX3gmbvwho5h3SPmAFmWKDHtd FfPjpSXXha1hkvRu69xQicm78F8tlXfrEJkWmf4F3krnA5xNmT1XUQau1daAwILFlrjU 8RvQ== X-Forwarded-Encrypted: i=1; AJvYcCUMbH/mhVwpabaiMr3vX4uV4/KSzuAXxBMvQ0vA2+AMw618SwB3kyTZi9c32wZxbzjW3P4N0NtD9FjsOe1Z2VVhW1XRHMg= X-Gm-Message-State: AOJu0YyeHMF5Ol6isSMqt9xhYud62rkyAKxolTJkCx0+jHlgNVCsFHGk cyUuGHTulcI6EsRZ2LuLlJ/447isWZBRYBZ6fbpH3peTg9L76kWUa+Oat23zFgDii4jCXN8lHcQ yOJZS9D4098AKPad/POsWpNjXAMWRrw== X-Google-Smtp-Source: AGHT+IELKX4sGK9/sRTX0Q7zt8UWGrhbYag/zdTmunDBsCM0vchWJGC3ucHdilB81fD2DrBbL6nlMcmvSuh8wnKYSYY= X-Received: by 2002:a05:6512:3246:b0:523:963b:3a1a with SMTP id 2adb3069b0e04-52964ea972bmr5566597e87.17.1716825089084; Mon, 27 May 2024 08:51:29 -0700 (PDT) In-Reply-To: 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:286052 Archived-At: By the way Troy, can you show your indent-region-function based on eglot-format? I once tried this and it didn't work very well. With the clangd server. Would like to see your attempt. Jo=C3=A3o On Mon, May 27, 2024 at 4:45=E2=80=AFPM Jo=C3=A3o T=C3=A1vora wrote: > > merge 70958 70835 > thanks > > On Mon, May 27, 2024 at 3:32=E2=80=AFPM Troy Brown wrote: > > > > On Mon, May 27, 2024 at 10:09=E2=80=AFAM Jo=C3=A3o T=C3=A1vora wrote: > > > > > > Bugs are only "legitimate" when they are harming someone somewhere. > > > This hook has been there for a number of years, and noone has complai= ned > > > that I can remember. If you have a use for the on-shutdown, then it's > > > a bug. It'd help to know about this use case. If you don't have a us= e, > > > it's just a doc bug, and patches welcome. > > Actually I was wrong. I have been recently warned of this exact > same issue. I thought you and that person were the same. > bug#70835, which this bug is a duplicate of (so I've merged them, > hopefully) > > > The use case is that I was experimenting with updating the > > buffer-local indent-region-function (and indirectly > > indent-line-function) to be based on eglot-format when the buffer was > > connected to the language server. I was attempting to use the > > eglot-managed-mode-hook so I could update these variables when the > > Eglot buffer management changed. Since the hook wasn't being called > > on shutdown it would still attempt to call eglot-format when it was no > > longer managing the buffer. The workaround was to use a mode-specific > > function for indent-region-function and then having that call > > eglot-managed-p to determine if it should call eglot-format or > > something else (e.g., indent-relative). > > Anyway, to your use case. The "off" hook would solve your problem, > but not as well as your solution. When setting variables, there's > no clean solution to the "undo problem", unless the variable in > question is a hook. Think: > > var is originally X > activate minor mode foo, saves var value of X, sets to Y, > activate minor mode bar, that also sets var, saves Y, sets to Z > deactivate foo, sets var to X > deactivate bar, sets var to Y > now both modes are inactive, variable is set to Y, in error > > When the variable being affected is a hook with certain rules, this > problem doesn't exist. > > Anyway, it's not a problem for Eglot to solve. So given there is > also bug#70835 requesting the same, I think we can risk just running > eglot-managed-mode-hook like so let's try this patch: > > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el > index 6896baf30ce..2fab9e7f38b 100644 > --- a/lisp/progmodes/eglot.el > +++ b/lisp/progmodes/eglot.el > @@ -2059,6 +2059,7 @@ eglot--managed-mode > (when eglot--current-flymake-report-fn > (eglot--report-to-flymake nil) > (setq eglot--current-flymake-report-fn nil)) > + (run-hooks 'eglot-managed-mode-hook) > (let ((server eglot--cached-server)) > (setq eglot--cached-server nil) > (when server > > There will possibly be people complaining we broke their configs, > so this might not be the end of the story. But it's reasonable to try it > since this is how the documentation says it _should_ work and is > consistent with the normal minor-mode hooks. > > Jo=C3=A3o --=20 Jo=C3=A3o T=C3=A1vora