doomemacs/modules/lang/sh/config.el

100 lines
3.4 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
2019-08-28 00:15:33 +10:00
'("cat" "cd" "chmod" "chown" "cp" "curl" "date" "echo" "find" "git" "grep"
"kill" "less" "ln" "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
(use-package! sh-script ; built-in
:mode ("\\.bats\\'" . sh-mode)
:mode ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode)
:mode ("/bspwmrc\\'" . sh-mode)
2016-05-13 00:29:07 -04:00
:config
2021-03-02 18:24:31 +07:00
(set-docsets! 'sh-mode "Bash")
(set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
(set-formatter! 'shfmt
'("shfmt" "-ci"
("-i" "%d" (unless indent-tabs-mode tab-width))
("-ln" "%s" (pcase sh-shell (`bash "bash") (`mksh "mksh") (_ "posix")))))
(set-repl-handler! 'sh-mode #'+sh/open-repl)
(set-lookup-handlers! 'sh-mode :documentation #'+sh-lookup-documentation-handler)
(set-ligatures! 'sh-mode
;; Functional
:def "function"
;; Types
:true "true" :false "false"
;; Flow
:not "!"
:and "&&" :or "||"
:in "in"
:for "for"
:return "return"
;; Other
:dot "." :dot "source")
2020-01-07 14:50:13 +02:00
(when (featurep! +lsp)
(add-hook 'sh-mode-local-vars-hook #'lsp! 'append))
2020-01-07 14:50:13 +02:00
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
:boom: revise advice naming convention (1/2) This is first of three big naming convention updates that have been a long time coming. With 2.1 on the horizon, all the breaking updates will batched together in preparation for the long haul. In this commit, we do away with the asterix to communicate that a function is an advice function, and we replace it with the '-a' suffix. e.g. doom*shut-up -> doom-shut-up-a doom*recenter -> doom-recenter-a +evil*static-reindent -> +evil--static-reindent-a The rationale behind this change is: 1. Elisp's own formatting/indenting tools would occasionally struggle with | and * (particularly pp and cl-prettyprint). They have no problem with / and :, fortunately. 2. External syntax highlighters (like pygmentize, discord markdown or github markdown) struggle with it, sometimes refusing to highlight code beyond these symbols. 3. * and | are less expressive than - and -- in communicating the intended visibility, versatility and stability of a function. 4. It complicated the regexps we must use to search for them. 5. They were arbitrary and over-complicated to begin with, decided on haphazardly way back when Doom was simply "my private config". Anyhow, like how predicate functions have the -p suffix, we'll adopt the -a suffix for advice functions, -h for hook functions and -fn for variable functions. Other noteable changes: - Replaces advice-{add,remove}! macro with new def-advice! macro. The old pair weren't as useful. The new def-advice! saves on a lot of space. - Removed "stage" assertions to make sure you were using the right macros in the right place. Turned out to not be necessary, we'll employ better checks later.
2019-07-18 15:42:52 +02:00
(advice-add #'sh-set-shell :around #'doom-shut-up-a)
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')
(add-hook! 'sh-mode-hook
(defun +sh-init-extra-fontification-h ()
(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 'symbols)
(0 'font-lock-type-face append))))))
;; 4. Fontify delimiters by depth
(add-hook 'sh-mode-hook #'rainbow-delimiters-mode)
;; autoclose backticks
(sp-local-pair 'sh-mode "`" "`" :unless '(sp-point-before-word-p sp-point-before-same-p)))
2017-02-19 18:57:16 -05:00
(use-package! company-shell
:when (featurep! :completion company)
2020-01-07 14:50:13 +02:00
:unless (featurep! +lsp)
:after sh-script
2017-03-20 16:32:29 -04:00
:config
(set-company-backend! 'sh-mode '(company-shell company-files))
(setq company-shell-delete-duplicates t
;; whatis lookups are exceptionally slow on macOS (#5860)
company-shell-dont-fetch-meta IS-MAC))
(use-package! fish-mode
2018-07-18 15:56:55 -04:00
:when (featurep! +fish)
:defer t
:config (set-formatter! 'fish-mode #'fish_indent))
2020-08-23 12:16:25 +01:00
(use-package! powershell
:when (featurep! +powershell)
:defer t
:config
(when (featurep! +lsp)
(add-hook 'powershell-mode-local-vars-hook #'lsp! 'append)))
;; Tree sitter
(eval-when! (featurep! +tree-sitter)
(add-hook! 'sh-mode-hook #'turn-on-tree-sitter-mode))