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#68547: [PATCH] ; Fix 'mode-line-format-right-align' with ElDoc Date: Sat, 20 Jan 2024 18:08:35 +0000 Message-ID: References: <83cytwtjiw.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="35244"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 68547@debbugs.gnu.org To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 20 19:09:18 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 1rRFmQ-0008yH-5Q for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Jan 2024 19:09:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRFmB-000825-E9; Sat, 20 Jan 2024 13:09:03 -0500 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 1rRFm8-00081x-Up for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2024 13:09:01 -0500 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 1rRFm8-0000My-Fj for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2024 13:09:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rRFmA-0008WL-Cw for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2024 13:09:02 -0500 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: Sat, 20 Jan 2024 18:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68547 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68547-submit@debbugs.gnu.org id=B68547.170577413932744 (code B ref 68547); Sat, 20 Jan 2024 18:09:02 +0000 Original-Received: (at 68547) by debbugs.gnu.org; 20 Jan 2024 18:08:59 +0000 Original-Received: from localhost ([127.0.0.1]:35702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rRFm6-0008W4-Qt for submit@debbugs.gnu.org; Sat, 20 Jan 2024 13:08:59 -0500 Original-Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:55738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rRFm4-0008Vl-6D for 68547@debbugs.gnu.org; Sat, 20 Jan 2024 13:08:58 -0500 Original-Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-50e759ece35so1820696e87.3 for <68547@debbugs.gnu.org>; Sat, 20 Jan 2024 10:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705774127; x=1706378927; 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=06FA/1+vhip+odHmcGW8n6OMHtLqglxz53oEES5ejv8=; b=O7O4pcVqGI+HauE0xBSSWpX66AnuA8bMAqAAcYw4RVzY1TVa/LElHCnt2q5m/SpNBu 0e3AdAU1ZYJs4R22tZiMZDfsWI5wFxuejj6ir/FnbOpXYV0tI5CHId31yjv2+NLiASLr EypXZ24zGUDY3q68Hb2HYCOjRXx8pce2jsX+m7RT58U+c7NUYon0XTlT8tPck+J/+5P5 n6EQbmaZZ0tTH1Wdp+bnUyhnuvN1gRnuxbib6DPN0nVV64BduAOLUiOP1dgLyiwyD68O YGa1fT3rruRLKt/uw1tZMRMLornufOqHzMzIZkGkSfr08oaASmsICo3wndtsWeQWRzPu TbvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705774127; x=1706378927; 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=06FA/1+vhip+odHmcGW8n6OMHtLqglxz53oEES5ejv8=; b=hnzZvXTiMnj3VfVOhqhrvHNBag9IeuPChxF/pe5KbsjVdGxX9zAuwhdlz6fVDw4Rro vUWLff7Wnf0BTSGzVTvI9/SkCA4QAzaNc9cvsGKGEAFCqmIaLWRh/PuIxq7nqjQKlZes 1WXVp+nhh9P4E7HJpMHicPsM9cgUjzUp0TdWzadQBYDjHLCN78RHs7TqLYiAY/aku5Xj nUVwXOVoiPOlNZ+HkToVxR3ugOaMb/hINeqSYy5NSQtnnARtpdWJzsbO401w+MSy00c9 5eKl2WMUAlNyZx/GdBKWmF+1rS57T+l3LOKci95Cz2XA1qEj3N3kExLy1UriK9rc/7R5 orxA== X-Gm-Message-State: AOJu0YxGEhoJ9l9GUXoUWABHMLYxzD+M43JhZbzCc5VmzWtm8czOaI3/ 3cMyBX8iT5f8N7MeJozy4Y81qsN/ui1nAEyNqXf+2gfe0Nscqk0l4z7mCs5xw2C3fljETtDoUN7 aCbogCwFoBN7BoEy07RzwSlIxfko= X-Google-Smtp-Source: AGHT+IFvdQ29CYUqXHF8WteS6K/ua5VbE+aHjhX1tvIiknphhabg0vds5NAWsX7n3B2pqkZE0p1j1Cfps4Cg1jFJyvc= X-Received: by 2002:a05:6512:3592:b0:50e:6e41:2f2a with SMTP id m18-20020a056512359200b0050e6e412f2amr502488lfr.6.1705774126548; Sat, 20 Jan 2024 10:08:46 -0800 (PST) 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:278620 Archived-At: On Sat, Jan 20, 2024 at 3:33=E2=80=AFPM Eshel Yaron wro= te: > Then I tried the following (somewhat pathological) use case: > > 0. Setup: (keymap-global-set "C-x w a" #'windmove-swap-states-left) > 1. Open two buffers in two windows side by side. > 2. Say `M-: (car `, to show info in the mode line of the left window. > 3. Without quitting the minibuffer, use `C-x o` to switch to the right > window, followed by `C-x w a` to switch the buffers in the left and > right windows. > 4. Return to the minibuffer and type `nil) RET` or something like that > to exit the minibuffer. > 5. The `mode-line-format` of the left buffer is becomes nil, i.e. no mode= line. > > Shuffling `mode-line-format` around is really tricky :( Indeed. Your case is pathological, but not particularly hard to trigger. Given the consequences are somewhat dire (vanished mode-line) , it should most definitely be handled. Try this version, please. Only difference is it uses a setq-local for eldoc--saved-mlf instead of a setq. Please give it as much testing as you can. Jo=C3=A3o diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index 912a7357ca7..1ba4e6a006f 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -182,7 +182,7 @@ eldoc-current-idle-delay "Idle time delay currently in use by timer. This is used to determine if `eldoc-idle-delay' is changed by the user.") -(defvar eldoc-message-function #'eldoc-minibuffer-message +(defvar eldoc-message-function #'eldoc--minibuffer-message "The function used by `eldoc--message' to display messages. It should receive the same arguments as `message'.") @@ -292,43 +292,42 @@ eldoc-schedule-timer (setq eldoc-current-idle-delay eldoc-idle-delay) (timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) -(defvar eldoc-mode-line-string nil) -(put 'eldoc-mode-line-string 'risky-local-variable t) - -(defun eldoc-minibuffer-message (format-string &rest args) +(defvar eldoc--saved-mlf nil + "Saved `mode-line-format' used in `eldoc--minibuffer-message'.") +(defun eldoc--minibuffer-message (format-string &rest args) "Display message specified by FORMAT-STRING and ARGS on the mode-line as needed. This function displays the message produced by formatting ARGS with FORMAT-STRING on the mode line when the current buffer is a minibuffe= r. Otherwise, it displays the message like `message' would." - (if (or (bound-and-true-p edebug-mode) (minibufferp)) - (progn - (add-hook 'post-command-hook #'eldoc-minibuffer--cleanup) - (with-current-buffer - (window-buffer - (or (window-in-direction 'above (minibuffer-window)) - (minibuffer-selected-window) - (get-largest-window))) - (when (and mode-line-format - (not (and (listp mode-line-format) - (assq 'eldoc-mode-line-string mode-line-format)))) - (setq mode-line-format - (funcall - (if (listp mode-line-format) #'append #'list) - (list "" '(eldoc-mode-line-string - (" " eldoc-mode-line-string " "))) - mode-line-format))) - (setq eldoc-mode-line-string - (when (stringp format-string) - (apply #'format-message format-string args))) - (force-mode-line-update))) - (apply #'message format-string args))) - -(defun eldoc-minibuffer--cleanup () - (unless (or (bound-and-true-p edebug-mode) (minibufferp)) - (setq eldoc-mode-line-string nil - ;; https://debbugs.gnu.org/16920 - eldoc-last-message nil) - (remove-hook 'post-command-hook #'eldoc-minibuffer--cleanup))) + (cond ((bound-and-true-p edebug-mode) + (eldoc--message-in-mode-line 'edebug-mode-hook format-string args= )) + ((minibufferp) + (eldoc--message-in-mode-line 'minibuffer-exit-hook format-string args)) + (t + (apply #'message format-string args)))) + +(defun eldoc--message-in-mode-line (hook format-string args) + (with-current-buffer + (window-buffer + (or (window-in-direction 'above (minibuffer-window)) + (minibuffer-selected-window) + (get-largest-window))) + (let ((buf (current-buffer))) + (cl-labels ((cleanup () + (with-current-buffer buf + (remove-hook hook #'cleanup) + (setq mode-line-format eldoc--saved-mlf + eldoc--saved-mlf nil)))) + (add-hook hook #'cleanup) + (setq-local eldoc--saved-mlf (or eldoc--saved-mlf mode-line-format= )) + (when format-string + (setq-local + mode-line-format + (funcall (if (listp eldoc--saved-mlf) #'cons #'list) + (and format-string + (apply #'format-message format-string args)) + eldoc--saved-mlf))) + (force-mode-line-update))))) (make-obsolete 'eldoc-message "use `eldoc-documentation-functions' instead." "eldoc-1.1.= 0") --=20 Jo=C3=A3o T=C3=A1vora