Locate password icon in global-mode-string

* doc/emacs/mini.texi (Passwords): Precise the location of the
password icon.

* doc/lispref/minibuf.texi (Reading a Password): The password icon
is added to global-mode-string.

* lisp/auth-source.el (read-passwd--mode-line-buffer): Remove.
(read-passwd--hide-password): Fix docstring.
(read-passwd-toggle-visibility): Don't use
`read-passwd--mode-line-buffer'.  Check for `read-passwd-mode'.
Force update in all mode lines.
(read-passwd-mode): Set `read-passwd--mode-line-icon' in
`global-mode-string'.  (Bug#73768)
This commit is contained in:
Michael Albinus 2024-10-18 17:47:43 +02:00
parent 19049efd30
commit 7dbbd58d6c
3 changed files with 19 additions and 29 deletions

View file

@ -975,8 +975,8 @@ password. You may type either @key{RET} or @key{ESC} to submit the
password. Any other self-inserting character key inserts the associated password. Any other self-inserting character key inserts the associated
character into the password, and all other input is ignored. character into the password, and all other input is ignored.
There is also an icon at the front of the mode line indicating the There is also an icon in the mode line indicating the password
password visibility. Clicking @kbd{mouse-1} on it toggles the password visibility. Clicking @kbd{mouse-1} on it toggles the password
visibility as well. visibility as well.
@node Yes or No Prompts @node Yes or No Prompts

View file

@ -2562,9 +2562,9 @@ This function uses @code{read-passwd-mode}, a minor mode. It binds two
keys in the minbuffer: @kbd{C-u} (@code{delete-minibuffer-contents}) keys in the minbuffer: @kbd{C-u} (@code{delete-minibuffer-contents})
deletes the password, and @kbd{TAB} deletes the password, and @kbd{TAB}
(@code{read-passwd--toggle-visibility}) toggles the visibility of the (@code{read-passwd--toggle-visibility}) toggles the visibility of the
password. There is also an additional icon in the mode-line. Clicking password. There is also an additional icon in the mode-line's
on this icon with @key{mouse-1} toggles the visibility of the password @code{global-mode-string}. Clicking on this icon with @key{mouse-1}
as well. toggles the visibility of the password as well.
@end defun @end defun
@node Minibuffer Commands @node Minibuffer Commands

View file

@ -2467,14 +2467,11 @@ point is moved into the passwords (see `authinfo-hide-elements').
:version "30.1" :version "30.1"
:help-echo "mouse-1: Toggle password visibility") :help-echo "mouse-1: Toggle password visibility")
(defvar read-passwd--mode-line-buffer nil
"Buffer to modify `mode-line-format' for showing/hiding passwords.")
(defvar read-passwd--mode-line-icon nil (defvar read-passwd--mode-line-icon nil
"Propertized mode line icon for showing/hiding passwords.") "Propertized mode line icon for showing/hiding passwords.")
(defvar read-passwd--hide-password t (defvar read-passwd--hide-password t
"Toggle whether password should be hidden in minubuffer.") "Toggle whether password should be hidden in minibuffer.")
(defun read-passwd--hide-password () (defun read-passwd--hide-password ()
"Make password in minibuffer hidden or visible." "Make password in minibuffer hidden or visible."
@ -2497,8 +2494,8 @@ Adapt also mode line."
;; FIXME: In case of a recursive minibuffer, this may select the wrong ;; FIXME: In case of a recursive minibuffer, this may select the wrong
;; mini-buffer. ;; mini-buffer.
(with-current-buffer (window-buffer win) (with-current-buffer (window-buffer win)
(setq read-passwd--hide-password (not read-passwd--hide-password)) (when (memq 'read-passwd-mode local-minor-modes)
(with-current-buffer read-passwd--mode-line-buffer (setq read-passwd--hide-password (not read-passwd--hide-password))
(setq read-passwd--mode-line-icon (setq read-passwd--mode-line-icon
`(:propertize `(:propertize
,(if icon-preference ,(if icon-preference
@ -2514,8 +2511,8 @@ Adapt also mode line."
(define-key map [mode-line mouse-1] (define-key map [mode-line mouse-1]
#'read-passwd-toggle-visibility) #'read-passwd-toggle-visibility)
map)))) map))))
(force-mode-line-update)) (force-mode-line-update 'all)
(read-passwd--hide-password)))) (read-passwd--hide-password)))))
(defvar read-passwd-map (defvar read-passwd-map
;; BEWARE: `defconst' would purecopy it, breaking the sharing with ;; BEWARE: `defconst' would purecopy it, breaking the sharing with
@ -2534,25 +2531,18 @@ Adapt also mode line."
:keymap read-passwd-map :keymap read-passwd-map
:version "30.1" :version "30.1"
(setq read-passwd--hide-password nil (setq read-passwd--hide-password nil)
;; Stolen from `eldoc-minibuffer-message'. (or global-mode-string (setq global-mode-string '("")))
read-passwd--mode-line-buffer
(window-buffer
(or (window-in-direction 'above (minibuffer-window))
(minibuffer-selected-window)
(get-largest-window))))
(if read-passwd-mode (let ((mode-string '(:eval read-passwd--mode-line-icon)))
(with-current-buffer read-passwd--mode-line-buffer (if read-passwd-mode
;; Add `read-passwd--mode-line-icon'. ;; Add `read-passwd--mode-line-icon'.
(when (listp mode-line-format) (or (member mode-string global-mode-string)
(setq mode-line-format (setq global-mode-string
(cons '(:eval read-passwd--mode-line-icon) (append global-mode-string (list mode-string))))
mode-line-format))))
(with-current-buffer read-passwd--mode-line-buffer
;; Remove `read-passwd--mode-line-icon'. ;; Remove `read-passwd--mode-line-icon'.
(when (listp mode-line-format) (setq global-mode-string
(setq mode-line-format (cdr mode-line-format))))) (delete mode-string global-mode-string))))
(when read-passwd-mode (when read-passwd-mode
(read-passwd-toggle-visibility))) (read-passwd-toggle-visibility)))