diff options
| author | TEC | 2020-12-23 22:34:35 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-12-23 22:34:35 +0100 |
| commit | 3be0dc659fd1a5bc976a545c0bdeda9a3d39e084 (patch) | |
| tree | 8203abdc0a1a429d9e56e42a49698d397cb9d9ce | |
| parent | 33210c8dc07fe8e1aed302aff09cac9ba798a221 (diff) | |
| download | emacs-3be0dc659fd1a5bc976a545c0bdeda9a3d39e084.tar.gz emacs-3be0dc659fd1a5bc976a545c0bdeda9a3d39e084.zip | |
authinfo-mode: add option to not hide any elements (and add font-lock)
* lisp/auth-source.el (authinfo-hide-elements): New user option.
(authinfo--keywords): New variable.
(authinfo-mode): Use it.
(authinfo--hide-passwords): Use doc-face instead of warning for
the passwords.
(authinfo--toggle-display): Ditto.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/auth-source.el | 45 |
2 files changed, 41 insertions, 8 deletions
| @@ -1460,6 +1460,10 @@ that makes it a valid button. | |||
| 1460 | 1460 | ||
| 1461 | ** Miscellaneous | 1461 | ** Miscellaneous |
| 1462 | 1462 | ||
| 1463 | --- | ||
| 1464 | *** New user option 'authinfo-hide-elements'. | ||
| 1465 | This can be set to nil to inhibit hiding passwords in .authinfo files. | ||
| 1466 | |||
| 1463 | +++ | 1467 | +++ |
| 1464 | *** A number of new string manipulation functions have been added. | 1468 | *** A number of new string manipulation functions have been added. |
| 1465 | 'string-clean-whitespace', 'string-fill', 'string-limit', | 1469 | 'string-clean-whitespace', 'string-fill', 'string-limit', |
diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 50795ce7946..27cf94d3786 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el | |||
| @@ -2408,23 +2408,51 @@ MODE can be \"login\" or \"password\"." | |||
| 2408 | (list user password auth-info))) | 2408 | (list user password auth-info))) |
| 2409 | 2409 | ||
| 2410 | ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just | 2410 | ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just |
| 2411 | ;;; hides passwords). | 2411 | ;;; hides passwords and adds basic syntax highlighting). |
| 2412 | 2412 | ||
| 2413 | (defcustom authinfo-hidden "password" | 2413 | (defcustom authinfo-hidden "password" |
| 2414 | "Regexp matching elements in .authinfo/.netrc files that should be hidden." | 2414 | "Regexp matching elements in .authinfo/.netrc files that should be hidden." |
| 2415 | :type 'regexp | 2415 | :type 'regexp |
| 2416 | :version "27.1") | 2416 | :version "27.1") |
| 2417 | 2417 | ||
| 2418 | (defcustom authinfo-hide-elements t | ||
| 2419 | "Whether to use `authinfo-hidden' to hide elements in authinfo files." | ||
| 2420 | :type 'boolean | ||
| 2421 | :version "28.1") | ||
| 2422 | |||
| 2423 | (defvar authinfo--keywords | ||
| 2424 | '(("^#.*" . font-lock-comment-face) | ||
| 2425 | ("^\\(machine\\)[ \t]+\\([^ \t\n]+\\)" | ||
| 2426 | (1 font-lock-variable-name-face) | ||
| 2427 | (2 font-lock-builtin-face)) | ||
| 2428 | ("\\(login\\)[ \t]+\\([^ \t\n]+\\)" | ||
| 2429 | (1 font-lock-comment-delimiter-face) | ||
| 2430 | (2 font-lock-keyword-face)) | ||
| 2431 | ("\\(password\\)[ \t]+\\([^ \t\n]+\\)" | ||
| 2432 | (1 font-lock-comment-delimiter-face) | ||
| 2433 | (2 font-lock-doc-face)) | ||
| 2434 | ("\\(port\\)[ \t]+\\([^ \t\n]+\\)" | ||
| 2435 | (1 font-lock-comment-delimiter-face) | ||
| 2436 | (2 font-lock-type-face)) | ||
| 2437 | ("\\([^ \t\n]+\\)[, \t]+\\([^ \t\n]+\\)" | ||
| 2438 | (1 font-lock-constant-face) | ||
| 2439 | (2 nil)))) | ||
| 2440 | |||
| 2418 | ;;;###autoload | 2441 | ;;;###autoload |
| 2419 | (define-derived-mode authinfo-mode fundamental-mode "Authinfo" | 2442 | (define-derived-mode authinfo-mode fundamental-mode "Authinfo" |
| 2420 | "Mode for editing .authinfo/.netrc files. | 2443 | "Mode for editing .authinfo/.netrc files. |
| 2421 | 2444 | ||
| 2422 | This is just like `fundamental-mode', but hides passwords. The | 2445 | This is just like `fundamental-mode', but has basic syntax |
| 2423 | passwords are revealed when point moved into the password. | 2446 | highlighting and hides passwords. Passwords are revealed when |
| 2447 | point is moved into the passwords (see `authinfo-hide-elements'). | ||
| 2424 | 2448 | ||
| 2425 | \\{authinfo-mode-map}" | 2449 | \\{authinfo-mode-map}" |
| 2426 | (authinfo--hide-passwords (point-min) (point-max)) | 2450 | (font-lock-add-keywords nil authinfo--keywords) |
| 2427 | (reveal-mode)) | 2451 | (setq-local comment-start "#") |
| 2452 | (setq-local comment-end "") | ||
| 2453 | (when authinfo-hide-elements | ||
| 2454 | (authinfo--hide-passwords (point-min) (point-max)) | ||
| 2455 | (reveal-mode))) | ||
| 2428 | 2456 | ||
| 2429 | (defun authinfo--hide-passwords (start end) | 2457 | (defun authinfo--hide-passwords (start end) |
| 2430 | (save-excursion | 2458 | (save-excursion |
| @@ -2436,14 +2464,15 @@ passwords are revealed when point moved into the password. | |||
| 2436 | nil t) | 2464 | nil t) |
| 2437 | (when (auth-source-netrc-looking-at-token) | 2465 | (when (auth-source-netrc-looking-at-token) |
| 2438 | (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) | 2466 | (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) |
| 2439 | (overlay-put overlay 'display (propertize "****" | 2467 | (overlay-put overlay 'display |
| 2440 | 'face 'warning)) | 2468 | (propertize "****" 'face 'font-lock-doc-face)) |
| 2441 | (overlay-put overlay 'reveal-toggle-invisible | 2469 | (overlay-put overlay 'reveal-toggle-invisible |
| 2442 | #'authinfo--toggle-display))))))) | 2470 | #'authinfo--toggle-display))))))) |
| 2443 | 2471 | ||
| 2444 | (defun authinfo--toggle-display (overlay hide) | 2472 | (defun authinfo--toggle-display (overlay hide) |
| 2445 | (if hide | 2473 | (if hide |
| 2446 | (overlay-put overlay 'display (propertize "****" 'face 'warning)) | 2474 | (overlay-put overlay 'display |
| 2475 | (propertize "****" 'face 'font-lock-doc-face)) | ||
| 2447 | (overlay-put overlay 'display nil))) | 2476 | (overlay-put overlay 'display nil))) |
| 2448 | 2477 | ||
| 2449 | (provide 'auth-source) | 2478 | (provide 'auth-source) |