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