2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/sh/config.el -*- lexical-binding: t; -*-
|
2015-09-28 14:22:26 -04:00
|
|
|
|
2017-06-20 15:34:10 +02: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")
|
2017-11-05 21:25:01 +01:00
|
|
|
"A list of common shell commands to be fontified especially in `sh-mode'.")
|
2017-06-20 15:34:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-09-03 00:59:17 -04:00
|
|
|
;;; Packages
|
2017-06-20 15:34:10 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! sh-script ; built-in
|
2020-04-08 15:29:29 -04:00
|
|
|
:mode ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode)
|
2018-05-25 00:46:11 +02:00
|
|
|
:mode ("/bspwmrc\\'" . sh-mode)
|
2016-05-13 00:29:07 -04:00
|
|
|
:config
|
2018-06-15 12:30:56 +02:00
|
|
|
(set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
|
2019-02-18 01:56:38 -05:00
|
|
|
(set-repl-handler! 'sh-mode #'+sh/open-repl)
|
2020-08-12 18:52:14 -04:00
|
|
|
(set-ligatures! 'sh-mode
|
2020-07-14 01:48:06 +04:30
|
|
|
;; Functional
|
|
|
|
:def "function"
|
|
|
|
;; Types
|
|
|
|
:true "true" :false "false"
|
|
|
|
;; Flow
|
|
|
|
:not "!"
|
|
|
|
:and "&&" :or "||"
|
|
|
|
:in "in"
|
|
|
|
:for "for"
|
|
|
|
:return "return"
|
|
|
|
;; Other
|
|
|
|
:dot "." :dot "source")
|
2017-06-20 15:34:10 +02:00
|
|
|
|
2020-01-07 14:50:13 +02:00
|
|
|
(when (featurep! +lsp)
|
2020-02-10 02:39:26 -05:00
|
|
|
(add-hook 'sh-mode-local-vars-hook #'lsp!))
|
2020-01-07 14:50:13 +02:00
|
|
|
|
2016-04-20 01:50:55 -04:00
|
|
|
(setq sh-indent-after-continuation 'always)
|
|
|
|
|
2018-09-18 11:48:16 -04:00
|
|
|
;; [pedantry intensifies]
|
|
|
|
(setq-hook! 'sh-mode-hook mode-name "sh")
|
|
|
|
|
2017-10-21 14:49:57 +02:00
|
|
|
;; recognize function names with dashes in them
|
2018-06-23 16:48:58 +02:00
|
|
|
(add-to-list 'sh-imenu-generic-expression
|
|
|
|
'(sh (nil "^\\s-*function\\s-+\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?" 1)
|
|
|
|
(nil "^\\s-*\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*()" 1)))
|
2017-10-21 14:49:57 +02:00
|
|
|
|
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
|
|
|
|
2017-06-20 15:34:10 +02:00
|
|
|
;; 1. Fontifies variables in double quotes
|
|
|
|
;; 2. Fontify command substitution in double quotes
|
|
|
|
;; 3. Fontify built-in/common commands (see `+sh-builtin-keywords')
|
2019-07-28 14:52:59 +02:00
|
|
|
(add-hook! 'sh-mode-hook
|
2019-07-25 12:16:58 +02:00
|
|
|
(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))
|
2019-09-03 00:59:17 -04:00
|
|
|
(,(regexp-opt +sh-builtin-keywords 'symbols)
|
2019-07-25 12:16:58 +02:00
|
|
|
(0 'font-lock-type-face append))))))
|
2018-08-20 00:33:19 +02:00
|
|
|
;; 4. Fontify delimiters by depth
|
|
|
|
(add-hook 'sh-mode-hook #'rainbow-delimiters-mode)
|
2017-06-20 15:34:10 +02:00
|
|
|
|
2017-09-02 16:11:14 +02:00
|
|
|
;; autoclose backticks
|
2019-10-19 13:52:27 -04:00
|
|
|
(sp-local-pair 'sh-mode "`" "`" :unless '(sp-point-before-word-p sp-point-before-same-p)))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company-shell
|
2017-03-19 22:47:50 -04:00
|
|
|
:when (featurep! :completion company)
|
2020-01-07 14:50:13 +02:00
|
|
|
:unless (featurep! +lsp)
|
2016-04-23 22:08:46 -04:00
|
|
|
:after sh-script
|
2017-03-20 16:32:29 -04:00
|
|
|
:config
|
2018-06-15 02:58:12 +02:00
|
|
|
(set-company-backend! 'sh-mode '(company-shell company-files))
|
2017-03-20 16:32:29 -04:00
|
|
|
(setq company-shell-delete-duplicates t))
|
2016-04-23 22:08:46 -04:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! fish-mode
|
2018-07-18 15:56:55 -04:00
|
|
|
:when (featurep! +fish)
|
|
|
|
:defer t
|
2018-08-22 02:15:44 +02:00
|
|
|
:config (set-formatter! 'fish-mode #'fish_indent))
|
2020-08-23 12:16:25 +01:00
|
|
|
|
|
|
|
(use-package! powershell
|
2020-10-06 08:18:30 +01:00
|
|
|
:when (featurep! +powershell)
|
|
|
|
:config
|
|
|
|
(when (featurep! +lsp)
|
|
|
|
(add-hook 'powershell-mode-local-vars-hook #'lsp!)))
|