From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#69237: 30.0.50; Toggle password visibility Date: Fri, 23 Feb 2024 16:43:17 +0100 Message-ID: <8734tjrxt6.fsf@gmx.de> References: <87zfw0ttyp.fsf@gmx.de> <87h6i0xhbb.fsf@gmail.com> Reply-To: Michael Albinus Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32341"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 69237@debbugs.gnu.org To: =?UTF-8?Q?K=C3=A9vin?= Le Gouguec Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 23 17:01:22 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 1rdXzF-00087H-JO for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 23 Feb 2024 17:01:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdXxy-0006Hz-7d; Fri, 23 Feb 2024 11:00:02 -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 1rdXj5-0005dw-Dl for bug-gnu-emacs@gnu.org; Fri, 23 Feb 2024 10:44:39 -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 1rdXj5-0006NT-54 for bug-gnu-emacs@gnu.org; Fri, 23 Feb 2024 10:44:39 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rdXjS-0001nk-Mo for bug-gnu-emacs@gnu.org; Fri, 23 Feb 2024 10:45:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 23 Feb 2024 15:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69237 X-GNU-PR-Package: emacs X-Debbugs-Original-Cc: "Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors" , 69237@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17087030436758 (code B ref -1); Fri, 23 Feb 2024 15:45:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Feb 2024 15:44:03 +0000 Original-Received: from localhost ([127.0.0.1]:48869 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdXiT-0001kN-5u for submit@debbugs.gnu.org; Fri, 23 Feb 2024 10:44:03 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:51726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdXiQ-0001kB-V5 for submit@debbugs.gnu.org; Fri, 23 Feb 2024 10:44:00 -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 1rdXi3-0005Uf-3F for bug-gnu-emacs@gnu.org; Fri, 23 Feb 2024 10:43:35 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdXi0-00066e-9L for bug-gnu-emacs@gnu.org; Fri, 23 Feb 2024 10:43:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1708702998; x=1709307798; i=michael.albinus@gmx.de; bh=lKmCQCL6fjzgBZzmuUEa0F8P/WhlIoS15xtrzIbZL94=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=b4MvOCsZQouVCVIVwSyvMB3+pF+e5uQUSZG2hZGhOtBeSUkNz0Gb4UuzwabdKyCL UPtTWYe1D/cuPRmWXYTlSbK5WrWC05kHryJ7BIYcxpO386pk1DmTSm9lBqR2CV0mg 8WdZBQp4QF0pr6L47gE0UxMEcYBu+WGAQfMOz4eBIhOD4hlujXlvQhvYKKqPJe9UV TH6tJDkkXrZOVSy1CKlcbk37iaYMUIseiDf6H8FvZlojAch3hd1c5zu+OV3l28UsH aWbioXODlLKWnBCS3RFQOuoIk/lGIuOJ5OIyHR6Xy54pHErEXvrhhfPUIFtmW/uit Utf8f1nYbdrpaFS3OQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.39.16]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MQ5vc-1rHb0A1qhU-00M7OF; Fri, 23 Feb 2024 16:43:18 +0100 In-Reply-To: <87h6i0xhbb.fsf@gmail.com> ("=?UTF-8?Q?K=C3=A9vin?= Le Gouguec"'s message of "Thu, 22 Feb 2024 22:30:48 +0000") X-Provags-ID: V03:K1:haPgsuOgR67ZgKObRNZO6QEVJmuGiJZLqQB3k6Yia1S0Bu/6hyQ aBCzeZsRD6gizJp8KeiTkpInJKViXSMc345glQx055X2GIm4PmPKebkHzo4eT4+iOvP4bTs 5V0NqANwgPjWTVuBmg7PMvSD444KwqOxBIQTB9UPofQBqah8X34HtS0ZY8xuRsbNTxaDVCK MKLJwTqXsWNHL0UzF3lEQ== UI-OutboundReport: notjunk:1;M01:P0:jHrF/NxZHuo=;XSpMoh9e9IDj83bQ+CLZGmAAdTa vTBf6SIZHXPqkLrn2fRSHMDwWXwHZOrrQJJV5fvmo/75lOTW0N/g1CwI21n8KMG1DLDBmXiBl MBobo8EdoAyeLY9kKptOGDv8HSvfb3hk9uhSrzL5FauVx+CfzJPiUTg1eJYP5xDgyopmm4s1j Cl+GroHDHs2hjPMDHHeM4JG3TayDjHzBIO+NBMVFPGo0wEvwdTQdnboXz0+XqkLWy9JtbUkGI YJgXXbQaHbcGaxM7hwxWgOnz2xvvKqMT4+M9yakAs+e703HdoYe5ME1qDqnrCvkzxNvpGCSMC j+bszimGOrT7w1VLVZXImR4WFpAkdU6abbRxTvWibFTF01qv9BMGdOEi/Cb71JJPVQC0GAMuL XPJjW09Ov7orKagDAFMCi0tRojYTVt5+8cmwz2gTIiK4MtW/3kTP2kby7jcsNmAFiKwXMOTeW 9qk6hw5csUPg4lE8ARkcqJ2oto1W8FIdU+27x0Nz/9vl40YS8Y8FjdN77yuq1Q2No+Mox5Sv6 iTUqlPvmjWDNxgo9KdvB/0yF7gCdzNhmySZC56za2rQAkERQ7ZlkliMkOUky/ErNoBAiMWHq4 63UNFgoI9G0YcOm4VhkTMe9Yu5gJWIGSmsa1avqcG514aAN2hmLHOfDXZdJ9lAXJ4YwZ5Bse8 kSeyISezOK1zE0NZjTRYVBv4vUl3L3U+RoIAdsf6/qNMInatQHbcGvPlkGEI8BauCK/F3zZ7U r/41gaZmC3VdeKZ+XrpmJt3WKtySiCJHTPa3IKOjCXjKjmv+/uUr/YCq6x2OWl+vvR6dfu9Y Received-SPF: pass client-ip=212.227.17.20; envelope-from=michael.albinus@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:280502 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable K=C3=A9vin Le Gouguec writes: Hi K=C3=A9vin, > No strong feelings re. keybindings; I've been using C-c C-c because I > wanted something easy to mash, but TAB fits that criterion as well. Not > sure we can leverage any well-established mnemonic from other keymaps; > FWIW=E2=80=A6 > > * TAB could be familiar to some outline users, but they'll probably > associate that binding to (un)folding, not necessarily hiding/revealing; > > * hideshow has multiple bindings for "toggle-hiding", so not sure we can > count on any single one having enough "mindshare". > > (Not too worried about needing to input TAB verbatim - I tend to > naturally reach for C-q TAB when I need to do that, since in most > contexts Emacs has a useful command bound to TAB instead of > self-insert-command) There are not so many comments on the keybindings. I guess this is because only few people read the bug-gnu-emacs ML. Let's install this on master, and see who hollers :-) > Other than the keybinding, the only other musing I have is regarding the > indicator: wondering if icons.el could help trim some of the boilerplate > down. In any case, it would give the user some degree of control over > how the indicator is shown (via the icon-preference option) even if we > don't provide 'emoji nor 'symbol variants. > > Not overly familiar with that library though - if that's something you > think might be worth looking into, the define-icon forms in outline.el > might help you assess how helpful the library would actually be. That's a good idea. I've implemented it, see the reworked patch appended. And now with documentation. Best regards, Michael. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index aa27de72ba0..66dfdc93318 100644 =2D-- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -2562,6 +2562,14 @@ Reading a Password The optional argument @var{default} specifies the default password to return if the user enters empty input. If @var{default} is @code{nil}, then @code{read-passwd} returns the null string in that case. + +This function uses @code{read-passwd-mode}, a minor mode. It binds two +keys in the minbuffer: @kbd{C-u} (@code{delete-minibuffer-contents}) +deletes the password, and @kbd{TAB} +(@code{read-passwd--toggle-visibility}) toggles the visibility of the +password. there is also an additional icon in the mode-line. Clicking +on this icon with @key{mouse-1} toggles the visibility of the password +as well. @end defun @node Minibuffer Commands diff --git a/etc/NEWS b/etc/NEWS index 7b248c3fe78..4c9fe4bcb12 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -318,6 +318,12 @@ Previously, it was set to t but this broke remote fil= e name detection. ** Multi-character key echo now ends with a suggestion to use Help. Customize 'echo-keystrokes-help' to nil to prevent that. ++++ +** 'read-passwd' can toggle the visibility of passwords. +Use 'TAB' in the minibuffer to show or hide the password. Likewise, +there is an icon on the mode-line, which toggles the visibility of the +password when clicking with 'mouse-1'. + =0C * Editing Changes in Emacs 30.1 diff --git a/etc/images/README b/etc/images/README index a778d9ce6c3..77377d36b5a 100644 =2D-- a/etc/images/README +++ b/etc/images/README @@ -125,7 +125,7 @@ For more information see the adwaita-icon-theme reposi= tory at: https://gitlab.gnome.org/GNOME/adwaita-icon-theme -Emacs images and their source in the Adwaita/scalable directory: +Emacs images and their source in the Adwaita/symbolic directory: checked.svg ui/checkbox-checked-symbolic.svg unchecked.svg ui/checkbox-symbolic.svg @@ -137,3 +137,5 @@ Emacs images and their source in the Adwaita/scalable = directory: left.svg ui/pan-start-symbolic.svg right.svg ui/pan-end-symbolic.svg up.svg ui/pan-up-symbolic.svg + conceal.svg actions/view-conceal-symbolic.svg + reveal.svg actions/view-reveal-symbolic.svg diff --git a/etc/images/conceal.svg b/etc/images/conceal.svg new file mode 100644 index 00000000000..172b73ed3d3 =2D-- /dev/null +++ b/etc/images/conceal.svg @@ -0,0 +1,4 @@ + + + + diff --git a/etc/images/reveal.svg b/etc/images/reveal.svg new file mode 100644 index 00000000000..41ae3733a53 =2D-- /dev/null +++ b/etc/images/reveal.svg @@ -0,0 +1,4 @@ + + + + diff --git a/lisp/simple.el b/lisp/simple.el index 9a33049f4ca..3003de0f06a 100644 =2D-- a/lisp/simple.el +++ b/lisp/simple.el @@ -10858,6 +10858,85 @@ visible-mode (setq-local vis-mode-saved-buffer-invisibility-spec buffer-invisibility-spec) (setq buffer-invisibility-spec nil))) + +=0C +(defvar read-passwd--mode-line-buffer nil + "Buffer to modify `mode-line-format' for showing/hiding passwords.") + +(defvar read-passwd--mode-line-icon nil + "Propertized mode line icon for showing/hiding passwords.") + +(defun read-passwd--toggle-visibility () + "Toggle minibuffer contents visibility. +Adapt also mode line." + (interactive) + (setq read-passwd--hide-password (not read-passwd--hide-password)) + (with-current-buffer read-passwd--mode-line-buffer + (setq read-passwd--mode-line-icon + `(:propertize + ,(icon-string + (if read-passwd--hide-password + 'read-passwd--show-password-icon + 'read-passwd--hide-password-icon)) + mouse-face mode-line-highlight + local-map + (keymap + (mode-line keymap (mouse-1 . read-passwd--toggle-visibility)= )))) + (force-mode-line-update)) + (read-passwd--hide-password)) + +(define-minor-mode read-passwd-mode + "Toggle visibility of password in minibuffer." + :group 'mode-line + :group 'minibuffer + :keymap read-passwd-map + :version "30.1" + + (require 'icons) + ;; It would be preferable to use "=F0=9F=91=81" ("\N{EYE}"). However, = there is + ;; no corresponding Unicode char with a slash. So we use symbols as + ;; fallback only, with "=E2=A6=B5" ("\N{CIRCLE WITH HORIZONTAL BAR}") f= or + ;; hiding the password. + (define-icon read-passwd--show-password-icon nil + '((image "reveal.svg" :height (0.8 . em)) + (symbol "=F0=9F=91=81") + (text "")) + "Mode line icon to show a hidden password." + :group mode-line-faces + :version "30.1" + :help-echo "mouse-1: Toggle password visibility") + (define-icon read-passwd--hide-password-icon nil + '((image "conceal.svg" :height (0.8 . em)) + (symbol "=E2=A6=B5") + (text "")) + "Mode line icon to hide a visible password." + :group mode-line-faces + :version "30.1" + :help-echo "mouse-1: Toggle password visibility") + + (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)))) + + (if read-passwd-mode + (with-current-buffer read-passwd--mode-line-buffer + ;; Add `read-passwd--mode-line-icon'. + (when (listp mode-line-format) + (setq mode-line-format + (cons '(:eval read-passwd--mode-line-icon) + mode-line-format)))) + (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))))) + + (when read-passwd-mode + (read-passwd--toggle-visibility))) + =0C (defvar messages-buffer-mode-map (let ((map (make-sparse-keymap))) diff --git a/lisp/subr.el b/lisp/subr.el index c317d558e24..555d0084545 100644 =2D-- a/lisp/subr.el +++ b/lisp/subr.el @@ -3375,14 +3375,23 @@ read-passwd-map (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map "\C-u" #'delete-minibuffer-contents) ;bug#12570 + (define-key map "\t" #'read-passwd--toggle-visibility) map) "Keymap used while reading passwords.") -(defun read-password--hide-password () +(defvar read-passwd--hide-password t) + +(defun read-passwd--hide-password () + "Make password in minibuffer hidden or visible." (let ((beg (minibuffer-prompt-end))) (dotimes (i (1+ (- (buffer-size) beg))) - (put-text-property (+ i beg) (+ 1 i beg) - 'display (string (or read-hide-char ?*)))))) + (if read-passwd--hide-password + (put-text-property + (+ i beg) (+ 1 i beg) 'display (string (or read-hide-char ?*))= ) + (remove-list-of-text-properties (+ i beg) (+ 1 i beg) '(display))= ) + (put-text-property + (+ i beg) (+ 1 i beg) + 'help-echo "C-u: Clear password\nTAB: Toggle password visibility")= ))) (defun read-passwd (prompt &optional confirm default) "Read a password, prompting with PROMPT, and return it. @@ -3420,18 +3429,20 @@ read-passwd (setq-local inhibit-modification-hooks nil) ;bug#15501. (setq-local show-paren-mode nil) ;bug#16091. (setq-local inhibit--record-char t) - (add-hook 'post-command-hook #'read-password--hide-password n= il t)) + (read-passwd-mode 1) + (add-hook 'post-command-hook #'read-passwd--hide-password nil= t)) (unwind-protect (let ((enable-recursive-minibuffers t) (read-hide-char (or read-hide-char ?*))) (read-string prompt nil t default)) ; t =3D "no history" (when (buffer-live-p minibuf) (with-current-buffer minibuf + (read-passwd-mode -1) ;; Not sure why but it seems that there might be cases wher= e the ;; minibuffer is not always properly reset later on, so und= o ;; whatever we've done here (bug#11392). (remove-hook 'after-change-functions - #'read-password--hide-password 'local) + #'read-passwd--hide-password 'local) (kill-local-variable 'post-self-insert-hook) ;; And of course, don't keep the sensitive data around. (erase-buffer)))))))) --=-=-=--