unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] add basic syntax highlighting to authinfo-mode
@ 2020-12-23 19:19 TEC
  2020-12-23 21:36 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: TEC @ 2020-12-23 19:19 UTC (permalink / raw)
  To: Emacs developers

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

Hello all,

I have a little aesthetic modification to authinfo-mode that I've been
using and find rather good that I thought I'd share for upstreaming :)

This just adds some basic font-lock keywords to recognise "param value"
pairs, and give special attention to "machine", "login", "port", and
"password".

See a sample of the output here: https://0x0.st/iCvE.png

Personally, I find this make my authinfo file a lot easier to parse at a
glance.

Additionally you may find a second patch which just adds a simple toggle
to turn off password hiding. I find this occasionally useful when I am
specifically looking at my passwords.

Hopefully others may find this little modification useful :)

I'm already an FSF-assigned contributor through Org, hopefully that
suffices here.

Happy holidays!

Timothy.


P.S. this is my first contribution to Emacs itself, so please let me
know if I've committed some faux-pas with commit message format etc.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-authinfo-mode-add-syntax-highlighting.patch --]
[-- Type: text/x-patch, Size: 3332 bytes --]

From 4c18961277904cbe2c9359b5b88d9bd17fa63aa8 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Thu, 24 Dec 2020 03:08:19 +0800
Subject: [PATCH 1/2] authinfo-mode: add syntax highlighting

Add syntax highlighting for general "param value..." pattern, as well as
specific common parameters: "machine", "login", "port", and "password".

Also format lines starting with "#" as comments, and change the face of
passwords from "warning" to "font-lock-doc-face".
---
 lisp/auth-source.el | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 50795ce..275a02c 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -2408,7 +2408,7 @@ MODE can be \"login\" or \"password\"."
     (list user password auth-info)))
 
 ;;; Tiny mode for editing .netrc/.authinfo modes (that basically just
-;;; hides passwords).
+;;; hides passwords and adds basic syntax highlighting).
 
 (defcustom authinfo-hidden "password"
   "Regexp matching elements in .authinfo/.netrc files that should be hidden."
@@ -2419,13 +2419,34 @@ MODE can be \"login\" or \"password\"."
 (define-derived-mode authinfo-mode fundamental-mode "Authinfo"
   "Mode for editing .authinfo/.netrc files.
 
-This is just like `fundamental-mode', but hides passwords.  The
-passwords are revealed when point moved into the password.
+This is just like `fundamental-mode', but has basic syntax highlighting and
+hides passwords.  The passwords are revealed when point moved into the password.
 
 \\{authinfo-mode-map}"
+  (font-lock-add-keywords nil authinfo--keywords)
+  (setq-local comment-start "#")
+  (setq-local comment-end "")
   (authinfo--hide-passwords (point-min) (point-max))
   (reveal-mode))
 
+(defvar authinfo--keywords
+  '(("^#.*" . font-lock-comment-face)
+    ("^\\(machine\\)[ \t]+\\([^ \t\n]+\\)"
+     (1 font-lock-variable-name-face)
+     (2 font-lock-builtin-face))
+    ("\\(login\\)[ \t]+\\([^ \t\n]+\\)"
+     (1 font-lock-comment-delimiter-face)
+     (2 font-lock-keyword-face))
+    ("\\(password\\)[ \t]+\\([^ \t\n]+\\)"
+     (1 font-lock-comment-delimiter-face)
+     (2 font-lock-doc-face))
+    ("\\(port\\)[ \t]+\\([^ \t\n]+\\)"
+     (1 font-lock-comment-delimiter-face)
+     (2 font-lock-type-face))
+    ("\\([^ \t\n]+\\)[, \t]+\\([^ \t\n]+\\)"
+     (1 font-lock-constant-face)
+     (2 nil))))
+
 (defun authinfo--hide-passwords (start end)
   (save-excursion
     (save-restriction
@@ -2437,13 +2458,13 @@ passwords are revealed when point moved into the password.
         (when (auth-source-netrc-looking-at-token)
           (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
             (overlay-put overlay 'display (propertize "****"
-                                                      'face 'warning))
+                                                      'face 'font-lock-doc-face))
             (overlay-put overlay 'reveal-toggle-invisible
                          #'authinfo--toggle-display)))))))
 
 (defun authinfo--toggle-display (overlay hide)
   (if hide
-      (overlay-put overlay 'display (propertize "****" 'face 'warning))
+      (overlay-put overlay 'display (propertize "****" 'face 'font-lock-doc-face))
     (overlay-put overlay 'display nil)))
 
 (provide 'auth-source)
-- 
2.29.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-authinfo-mode-add-option-to-not-hide-any-elements.patch --]
[-- Type: text/x-patch, Size: 1443 bytes --]

From 8caf99ad038e8b21c33f6eac14bb73f96c00541b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Thu, 24 Dec 2020 03:16:05 +0800
Subject: [PATCH 2/2] authinfo-mode: add option to not hide any elements

New custom variable `authinfo-hide-elements-p' when set to nil prevents
calling `authinfo--hide-passwords' on activation of `authinfo-mode'.
---
 lisp/auth-source.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 275a02c..ba7cfeb 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -2415,6 +2415,11 @@ MODE can be \"login\" or \"password\"."
   :type 'regexp
   :version "27.1")
 
+(defcustom authinfo-hide-elements-p t
+  "Whether to use `authinfo-hidden' to hide elements in authinfo files."
+  :type 'boolean
+  :version "27.3")
+
 ;;;###autoload
 (define-derived-mode authinfo-mode fundamental-mode "Authinfo"
   "Mode for editing .authinfo/.netrc files.
@@ -2426,8 +2431,9 @@ hides passwords.  The passwords are revealed when point moved into the password.
   (font-lock-add-keywords nil authinfo--keywords)
   (setq-local comment-start "#")
   (setq-local comment-end "")
-  (authinfo--hide-passwords (point-min) (point-max))
-  (reveal-mode))
+  (when authinfo-hide-elements-p
+    (authinfo--hide-passwords (point-min) (point-max))
+    (reveal-mode)))
 
 (defvar authinfo--keywords
   '(("^#.*" . font-lock-comment-face)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] add basic syntax highlighting to authinfo-mode
  2020-12-23 19:19 [PATCH] add basic syntax highlighting to authinfo-mode TEC
@ 2020-12-23 21:36 ` Lars Ingebrigtsen
  2020-12-24  3:40   ` TEC
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-23 21:36 UTC (permalink / raw)
  To: TEC; +Cc: Emacs developers

TEC <tecosaur@gmail.com> writes:

> This just adds some basic font-lock keywords to recognise "param value"
> pairs, and give special attention to "machine", "login", "port", and
> "password".

Looks good; applied to Emacs 28 with some minor changes.

> P.S. this is my first contribution to Emacs itself, so please let me
> know if I've committed some faux-pas with commit message format etc.

The preferred way to generate the ChangeLog-style commit messages is
with the `C-x 4 a' command.

> +(defcustom authinfo-hide-elements-p t

I removed the -p, because we only use -p on functions, not variables.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] add basic syntax highlighting to authinfo-mode
  2020-12-23 21:36 ` Lars Ingebrigtsen
@ 2020-12-24  3:40   ` TEC
  0 siblings, 0 replies; 3+ messages in thread
From: TEC @ 2020-12-24  3:40 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Emacs developers


Lars Ingebrigtsen <larsi@gnus.org> writes:

> Looks good; applied to Emacs 28 with some minor changes.

Nice! Thanks for taking my little contribution :)

All the best,

Timothy.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-24  3:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 19:19 [PATCH] add basic syntax highlighting to authinfo-mode TEC
2020-12-23 21:36 ` Lars Ingebrigtsen
2020-12-24  3:40   ` TEC

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).