From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: TEC Newsgroups: gmane.emacs.devel Subject: [PATCH] add basic syntax highlighting to authinfo-mode Date: Thu, 24 Dec 2020 03:19:03 +0800 Message-ID: <87sg7wtja5.fsf@gmail.com> 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="16266"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 27.1 To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 23 20:31:11 2020 Return-path: Envelope-to: ged-emacs-devel@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 1ks9qo-0004A0-Gh for ged-emacs-devel@m.gmane-mx.org; Wed, 23 Dec 2020 20:31:10 +0100 Original-Received: from localhost ([::1]:39850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ks9qn-0006iH-G0 for ged-emacs-devel@m.gmane-mx.org; Wed, 23 Dec 2020 14:31:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ks9nR-0003lx-68 for emacs-devel@gnu.org; Wed, 23 Dec 2020 14:27:42 -0500 Original-Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:42675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ks9nM-00041B-2K for emacs-devel@gnu.org; Wed, 23 Dec 2020 14:27:40 -0500 Original-Received: by mail-pf1-x42e.google.com with SMTP id v2so10909803pfm.9 for ; Wed, 23 Dec 2020 11:27:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:date:message-id:mime-version; bh=+AgOZuvRqKL/z0PQS0+KCSZCSsSDT0oRbWQ53b/rM2Q=; b=mP3uki4hon5SrOzInhJviGfXH6NjwSdIGkVgHyUT5h1Zp+0pKJYlr0nDelaFCbmylJ 9D09HrSNvwlaxnWJJedsm1hVycvGgw9FbYv+AaRXxgd0Yah2f7OeZaCkZZFYnhss7uk2 cXs6htCNFl6oeoQlY/yjyS41n6QMO9BtrfWVkmNcJRWaO53cBFCcROD3SYC6ro+8kl+s w2cZvj2zbXj8+zdHbl0Aps3lNcIzM7y88HNr49Er3R9/Vzg9Syktiv7IynwIdpPhnZIu Yn9spMUlXoVsNMBtAAGerxhe2r6uqwWeQgOKuF/ZJ0Plxsygqr3hS6j9JvZADdcLoqS7 5Ruw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :mime-version; bh=+AgOZuvRqKL/z0PQS0+KCSZCSsSDT0oRbWQ53b/rM2Q=; b=PHBQMoyUAHvFTIZ2knglHWjGmpkLizLyv+pW2HNyEiQSri41PpkZ39i3xhpSFjfQ9L z9Np7PUCS9jdcogCisT1oB4gDtalGuqcpAtZWPjTWnhMa1Wk6QNsnAPOvkAFURyK68XT gS8ci2eUHacg2TaqcJf4TbDRhvzX9kYRbH+jYtS6FQk2CGR9x/Q8cePxucWDFvKd2lr4 V/y9+Yt7sUqTSRtC/9v3V8uS3V+tPjKSAl2zusPh6xxVhllklVrSAyv0I+mt1r6IyeXl wLjexqAwI4Uap3Calpor1VUzpnCDiYBF+yJhJZ+H94rCr/RpbYj9LovwW/CsGdk3UeXz d1Vg== X-Gm-Message-State: AOAM530Kyr6DUNunVSRPkJm3lEmNlwTvwKvsJ/Al3CGl5AwhoSpxV3Qu 7Gm3YBWpllKVwHfK14mxjrImGUAHVf8= X-Google-Smtp-Source: ABdhPJzr4/ROF49yGWBX2EVzTUEZMtSaFse50gtPy1Dx3qscUYhIupFCMut9L3ITRtfvtjKVh0VJVA== X-Received: by 2002:a63:cc01:: with SMTP id x1mr25123551pgf.378.1608751654319; Wed, 23 Dec 2020 11:27:34 -0800 (PST) Original-Received: from localhost (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id d8sm406828pjv.3.2020.12.23.11.27.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 11:27:33 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=tecosaur@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:261634 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-authinfo-mode-add-syntax-highlighting.patch >From 4c18961277904cbe2c9359b5b88d9bd17fa63aa8 Mon Sep 17 00:00:00 2001 From: TEC 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-authinfo-mode-add-option-to-not-hide-any-elements.patch >From 8caf99ad038e8b21c33f6eac14bb73f96c00541b Mon Sep 17 00:00:00 2001 From: TEC 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 --=-=-=--