unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: michael.albinus@gmx.de, 73768@debbugs.gnu.org
Subject: bug#73768: 'read-passwd-mode' can clobber user defined mode lines
Date: Sun, 13 Oct 2024 11:58:52 +0200	[thread overview]
Message-ID: <a81e9ced-3b0f-43b9-813e-c8ddddf3322a@gmx.at> (raw)
In-Reply-To: <87v7xxsj4l.fsf@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 2599 bytes --]

When in my Emacs with a stand alone minibuffer frame I create a shell
buffer and there do ssh-add, the following happens:

In the lines below 'wid' stands for the window in direction (nil in the
rows below because a stand alone minibuffer frame has no window above),
'msw' the minibuffer selected window, 'glw' the largest window (nil in
the first row below because a stand alone minibuffer frame has no
largest window) and 'sw' the selected window.  'add' and 'remove' stand
for adding and removing the icon. 'before' and 'after' stand for whether
we are before or after doing that.  These are followed by the value of
'read-passwd--mode-line-buffer' and the first two elements of that
buffer's mode line string.

wid .. nil .. msw .. #<window 11 on *shell*> .. glw .. nil .. sw .. #<window 8 on  *Minibuf-1*>
add before .. *shell* .. %e .. mode-line-version
add after .. *shell* .. (:eval read-passwd--mode-line-icon) .. %e
wid .. nil .. msw .. nil .. glw .. #<window 6 on .emacs> .. sw .. #<window 11 on *shell*>
remove before .. .emacs .. %e .. mode-line-version
remove after .. .emacs .. mode-line-version ..

So the window chosen for adding the icon is the value of calling
'minibuffer-selected-window' and everything is OK ('mode-line-version'
is a private variable of mine, ignore it).  The icon's buffer is *shell*
and the icon appears correctly.

But when the icon shall be removed, 'minibuffer-selected-window' returns
nil and the largest window is chosen instead which now happens to show
my init file .emacs.  ‘read-passwd’ leaves the icon in *shell* and kills
the mode line of my .emacs file.

The crucial fact is that the selected window changes from the minibuffer
window to the *shell* window because 'minibuffer-selected-window' is
specified as

   if (minibuf_level > 0
       && MINI_WINDOW_P (XWINDOW (selected_window))
       && WINDOW_LIVE_P (minibuf_selected_window))
     return minibuf_selected_window;

and *shell* is not a mini window.  So 'minibuffer-selected-window'
returns nil in the scenario at hand and the largest window of the
selected window's frame is chosen.  And the selected window obviously
changes because 'read-string' (and in further consequence read_minibuf)
restores the window selected before the minibuffer window was selected.

Concludingly, the current version works when 'window-in-direction'
returns a suitable window and may fail miserably otherwise.

The attached patch fixes the problem here.  But I still think that the
icon should appear in the prompt of 'read-passwd' itself.

martin

[-- Attachment #2: read-passwd.diff --]
[-- Type: text/x-patch, Size: 1430 bytes --]

diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 90b58f560c0..5353a7a55fe 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -2534,13 +2534,15 @@ read-passwd-mode
   :keymap read-passwd-map
   :version "30.1"
 
-  (setq read-passwd--hide-password nil
-        ;; Stolen from `eldoc-minibuffer-message'.
-        read-passwd--mode-line-buffer
-        (window-buffer
-         (or (window-in-direction 'above (minibuffer-window))
-	     (minibuffer-selected-window)
-	     (get-largest-window))))
+  (setq read-passwd--hide-password nil)
+  ;; Stolen from `eldoc-minibuffer-message'.
+  (unless (and (buffer-live-p read-passwd--mode-line-buffer)
+	       (get-buffer-window read-passwd--mode-line-buffer))
+    (setq read-passwd--mode-line-buffer
+          (window-buffer
+           (or (window-in-direction 'above (minibuffer-window))
+	       (minibuffer-selected-window)
+	       (get-largest-window)))))
 
   (if read-passwd-mode
       (with-current-buffer read-passwd--mode-line-buffer
@@ -2552,7 +2554,8 @@ read-passwd-mode
     (with-current-buffer read-passwd--mode-line-buffer
       ;; Remove `read-passwd--mode-line-icon'.
       (when (listp mode-line-format)
-        (setq mode-line-format (cdr mode-line-format)))))
+        (setq mode-line-format (cdr mode-line-format)))
+      (setq read-passwd--mode-line-buffer nil)))
 
   (when read-passwd-mode
     (read-passwd-toggle-visibility)))

  parent reply	other threads:[~2024-10-13  9:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-12  9:26 bug#73768: 'read-passwd-mode' can clobber user defined mode lines martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-12 10:36 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-12 13:56   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 13:49     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13  9:58   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-10-13 14:19     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 15:09       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 16:15         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-14 14:56           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-13 15:21       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a81e9ced-3b0f-43b9-813e-c8ddddf3322a@gmx.at \
    --to=bug-gnu-emacs@gnu.org \
    --cc=73768@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).