doomemacs/modules/lang/sh/config.el

76 lines
2.7 KiB
EmacsLisp
Raw Normal View History

;;; lang/sh/config.el -*- lexical-binding: t; -*-
2015-09-28 14:22:26 -04:00
(defvar +sh-builtin-keywords
'("cat" "cat" "cd" "chmod" "chown" "cp" "curl" "date" "echo" "find" "git"
"grep" "kill" "less" "ls" "make" "mkdir" "mv" "pgrep" "pkill" "pwd"
"rm" "sleep" "sudo" "touch")
"A list of common shell commands to be fontified especially in `sh-mode'.")
;;
;; Packages
(def-package! sh-script ; built-in
:mode ("\\.zunit\\'" . sh-mode)
:mode ("/bspwmrc\\'" . sh-mode)
:mode ("/bin/[^/]+\\'" . sh-mode)
2016-05-13 00:29:07 -04:00
:config
(set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
(set-repl-handler! 'sh-mode #'+sh/open-repl)
2016-04-20 01:50:55 -04:00
(setq sh-indent-after-continuation 'always)
;; [pedantry intensifies]
(setq-hook! 'sh-mode-hook mode-name "sh")
;; recognize function names with dashes in them
(add-to-list 'sh-imenu-generic-expression
'(sh (nil "^\\s-*function\\s-+\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?" 1)
(nil "^\\s-*\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*()" 1)))
2018-04-23 00:03:28 -04:00
;; `sh-set-shell' is chatty about setting up indentation rules
(advice-add #'sh-set-shell :around #'doom*shut-up)
2018-02-02 20:46:02 -05:00
;; 1. Fontifies variables in double quotes
;; 2. Fontify command substitution in double quotes
;; 3. Fontify built-in/common commands (see `+sh-builtin-keywords')
(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)
;; autoclose backticks
2018-12-22 04:01:17 -05:00
(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...
2017-02-19 18:57:16 -05:00
(defun +sh|detect-zsh ()
2017-06-20 16:18:27 +02:00
(when (or (and buffer-file-name
(string-match-p "\\.zsh\\'" buffer-file-name))
(save-excursion
(goto-char (point-min))
(looking-at-p "^#!.+/zsh[$ ]")))
2017-02-19 18:57:16 -05:00
(sh-set-shell "zsh")))
(add-hook 'sh-mode-hook #'+sh|detect-zsh))
2017-02-19 18:57:16 -05:00
(def-package! company-shell
:when (featurep! :completion company)
:after sh-script
2017-03-20 16:32:29 -04:00
:config
(set-company-backend! 'sh-mode '(company-shell company-files))
2017-03-20 16:32:29 -04:00
(setq company-shell-delete-duplicates t))
2018-08-21 02:57:40 +02:00
2018-07-18 15:56:55 -04:00
(def-package! fish-mode
:when (featurep! +fish)
:defer t
:config (set-formatter! 'fish-mode #'fish_indent))