From 87b685f4365f663ef1258cd60616034cd2cc89c9 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 23 Sep 2019 12:27:42 +0200 Subject: [PATCH] Add an `authinfo-hidden' variable * lisp/auth-source.el (authinfo-hidden): New variable. (authinfo--hide-passwords): Use it to allow users to decide what to hide. --- etc/NEWS | 3 ++- lisp/auth-source.el | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 73f0ca2497b..e28bb2c0bd9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1497,7 +1497,8 @@ To recover the previous behavior, set new user option *** .authinfo and .netrc files now use a new mode: 'authinfo-mode'. This is just like 'fundamental-mode', except that it hides passwords under a "****" display property. When the cursor moves to this text, -the real password is revealed (via 'reveal-mode'). +the real password is revealed (via 'reveal-mode'). The +'authinfo-hidden' variable can be used to control what to hide. ** Tramp diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 6d53a222e98..9061d41556f 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -2400,6 +2400,11 @@ MODE can be \"login\" or \"password\"." ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just ;;; hides passwords). +(defcustom authinfo-hidden "password" + "Regexp matching elements in .authinfo/.netrc files that should be hidden." + :type 'regexp + :version "27.1") + ;;;###autoload (define-derived-mode authinfo-mode fundamental-mode "Authinfo" "Mode for editing .authinfo/.netrc files. @@ -2416,13 +2421,15 @@ passwords are revealed when point moved into the password. (save-restriction (narrow-to-region start end) (goto-char start) - (while (re-search-forward "\\(\\s-\\|^\\)password\\s-+\\([^\n\t ]+\\)" + (while (re-search-forward (format "\\(\\s-\\|^\\)\\(%s\\)\\s-+" + authinfo-hidden) nil t) - (let ((overlay (make-overlay (match-beginning 2) (match-end 2)))) - (overlay-put overlay 'display (propertize "****" - 'face 'warning)) - (overlay-put overlay 'reveal-toggle-invisible - #'authinfo--toggle-display)))))) + (when (looking-at "[^\n\t ]+") + (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) + (overlay-put overlay 'display (propertize "****" + 'face 'warning)) + (overlay-put overlay 'reveal-toggle-invisible + #'authinfo--toggle-display))))))) (defun authinfo--toggle-display (overlay hide) (if hide -- 2.39.2