lang/sh: conform to new hook conventions

This commit is contained in:
Henrik Lissner 2019-07-25 12:16:58 +02:00
parent 4aa577ca3d
commit b24d7506e6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -34,7 +34,8 @@
;; 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')
(defun +sh|init-extra-fontification () (add-hook 'sh-mode-hook
(defun +sh-init-extra-fontification-h ()
(font-lock-add-keywords (font-lock-add-keywords
nil `((+sh--match-variables-in-quotes nil `((+sh--match-variables-in-quotes
(1 'font-lock-constant-face prepend) (1 'font-lock-constant-face prepend)
@ -42,8 +43,7 @@
(+sh--match-command-subst-in-quotes (+sh--match-command-subst-in-quotes
(1 'sh-quoted-exec prepend)) (1 'sh-quoted-exec prepend))
(,(regexp-opt +sh-builtin-keywords 'words) (,(regexp-opt +sh-builtin-keywords 'words)
(0 'font-lock-type-face append))))) (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)
@ -51,14 +51,14 @@
(sp-local-pair 'sh-mode "`" "`" :unless '(sp-point-before-word-p sp-point-before-same-p)) (sp-local-pair 'sh-mode "`" "`" :unless '(sp-point-before-word-p sp-point-before-same-p))
;; sh-mode has file extensions checks for other shells, but not zsh, so... ;; sh-mode has file extensions checks for other shells, but not zsh, so...
(defun +sh|detect-zsh () (add-hook 'sh-mode-hook
(defun +sh-detect-zsh-h ()
(when (or (and buffer-file-name (when (or (and buffer-file-name
(string-match-p "\\.zsh\\'" buffer-file-name)) (string-match-p "\\.zsh\\'" buffer-file-name))
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(looking-at-p "^#!.+/zsh[$ ]"))) (looking-at-p "^#!.+/zsh[$ ]")))
(sh-set-shell "zsh"))) (sh-set-shell "zsh")))))
(add-hook 'sh-mode-hook #'+sh|detect-zsh))
(use-package! company-shell (use-package! company-shell