lang/sh: extract extra fontification into hook

So it can apply to sh-mode derivatives, like direnv-envrc-mode.
This commit is contained in:
Henrik Lissner 2019-07-10 02:27:42 +02:00
parent e17e9a5c53
commit 3a2f156acd
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395

View File

@ -34,14 +34,16 @@
;; 1. Fontifies variables in double quotes
;; 2. Fontify command substitution in double quotes
;; 3. Fontify built-in/common commands (see `+sh-builtin-keywords')
(font-lock-add-keywords
'sh-mode `((+sh--match-variables-in-quotes
(1 'font-lock-constant-face prepend)
(2 'font-lock-variable-name-face prepend))
(+sh--match-command-subst-in-quotes
(1 'sh-quoted-exec prepend))
(,(regexp-opt +sh-builtin-keywords 'words)
(0 'font-lock-type-face append))))
(defun +sh|init-extra-fontification ()
(font-lock-add-keywords
nil `((+sh--match-variables-in-quotes
(1 'font-lock-constant-face prepend)
(2 'font-lock-variable-name-face prepend))
(+sh--match-command-subst-in-quotes
(1 'sh-quoted-exec prepend))
(,(regexp-opt +sh-builtin-keywords 'words)
(0 'font-lock-type-face append)))))
(add-hook 'sh-mode-hook #'+sh|init-extra-fontification)
;; 4. Fontify delimiters by depth
(add-hook 'sh-mode-hook #'rainbow-delimiters-mode)