Mode authinfo colouring into own package

This commit is contained in:
TEC 2020-10-25 03:13:45 +08:00
parent 2e2fb849b1
commit 1a88286ab4
3 changed files with 15 additions and 65 deletions

3
.gitmodules vendored
View File

@ -7,3 +7,6 @@
[submodule "org-pandoc-import"]
path = lisp/org-pandoc-import
url = https://github.com/tecosaur/org-pandoc-import.git
[submodule "authinfo-color-mode"]
path = lisp/authinfo-color-mode
url = https://github.com/tecosaur/authinfo-color-mode.git

View File

@ -1342,6 +1342,17 @@ Graphviz is a nice method of visualising simple graphs, based on plaintext
#+begin_src emacs-lisp
(package! graphviz-dot-mode :pin "3642a0a5f41a80c8ecef7c6143d514200b80e194")
#+end_src
*** Authinfo
#+begin_src emacs-lisp
(package! authinfo-color-mode
:recipe (:local-repo "lisp/authinfo-color-mode"))
#+end_src
Now we just need to load it appropriately.
#+begin_src emacs-lisp :tangle yes
(use-package! authinfo-color-mode
:mode ("authinfo.gpg\\'" . authinfo-color-mode)
:init (advice-add 'authinfo-mode :override #'authinfo-color-mode))
#+end_src
* Package configuration
** Abbrev mode
Thanks to [[https://emacs.stackexchange.com/questions/45462/use-a-single-abbrev-table-for-multiple-modes/45476#45476][use a single abbrev-table for multiple modes? - Emacs Stack Exchange]] I
@ -6733,68 +6744,3 @@ enable it for ~.beancount~ files.
:i "TAB" #'beancount-tab-dwim))
#+end_src
** Authinfo
I just like syntax highlighting. So, let's define a mode with some simple font
locking.
#+begin_src emacs-lisp :tangle lisp/authinfo-colour-mode.el :comments no
;;; authinfo-mode.el -*- lexical-binding: t; -*-
(setq authinfo-colour-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-colour--hide-passwords (start end)
"Just `authinfo--hide-passwords' with a different colour face overlay."
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char start)
(while (re-search-forward "\\bpassword +\\([^\n\t ]+\\)"
nil t)
(let ((overlay (make-overlay (match-beginning 1) (match-end 1))))
(overlay-put overlay 'display (propertize "****"
'face 'font-lock-doc-face))
(overlay-put overlay 'reveal-toggle-invisible
#'authinfo-colour--toggle-display))))))
(defun authinfo-colour--toggle-display (overlay hide)
"Just `authinfo--toggle-display' with a different colour face overlay."
(if hide
(overlay-put overlay 'display (propertize "****" 'face 'font-lock-doc-face))
(overlay-put overlay 'display nil)))
(defvar authinfo-hide-passwords t
"Whether to hide passwords in authinfo.")
(define-derived-mode authinfo-colour-mode fundamental-mode "Authinfo"
"Major mode for editing .authinfo files.
Like `fundamental-mode', just with colour and passoword hiding."
(font-lock-add-keywords nil authinfo-colour-keywords)
(setq-local comment-start "#")
(setq-local comment-end "")
(when authinfo-hide-passwords
(authinfo-colour--hide-passwords (point-min) (point-max))
(reveal-mode)))
(provide 'authinfo-colour-mode)
#+end_src
Now we just need to load it appropriately.
#+begin_src emacs-lisp
(use-package! authinfo-colour-mode
:mode ("authinfo\\.gpg\\'" . authinfo-colour-mode)
:init (advice-add 'authinfo-mode :override #'authinfo-colour-mode))
#+end_src

@ -0,0 +1 @@
Subproject commit b5be4d8d2227ae33d73f692716c3a57dd02fbc6c