summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennard <lennard.hofmann@web.de>2020-01-12 10:35:56 +0000
committerLennard Hofmann <lennard.hofmann@web.de>2020-01-12 11:41:12 +0100
commita8bbdc71d9c9e7ac1d50fdaee6ed3918ef93902b (patch)
tree321ff08b5762ccdcf4cefb1f3f25b0daad3b80d5
parentb85365bff85f5db3cf4a160dfad8b3590b6926a0 (diff)
[sh] Separate keywords and builtins; fix variables
Previously, the keywords were a mess. They contained the shell’s reserved words and some arbitrarily selected builtins. I generated the word list using bash because it contains all POSIX builtins and is common for scripting. In variable assignments some characters that are allowed to be in variables used to not be highlighted, e.g. hyphens. With this commit all characters except whitespace are considered to be part of the variable.
-rw-r--r--rc/filetype/sh.kak30
1 files changed, 24 insertions, 6 deletions
diff --git a/rc/filetype/sh.kak b/rc/filetype/sh.kak
index 272f2fa8..76c50264 100644
--- a/rc/filetype/sh.kak
+++ b/rc/filetype/sh.kak
@@ -30,11 +30,9 @@ add-highlighter shared/sh/double_string/fill fill string
evaluate-commands %sh{
# Grammar
- keywords="alias bind builtin caller case cd command coproc declare do done
- echo elif else enable esac exit fi for function help
- if in let local logout mapfile printf read readarray
- readonly return select set shift source test then
- time type typeset ulimit unalias until while break continue"
+ # Generated with `compgen -k` in bash
+ keywords="if then else elif fi case esac for select while until do done in
+ function time coproc"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
@@ -43,10 +41,30 @@ evaluate-commands %sh{
# Highlight keywords
printf %s "add-highlighter shared/sh/code/ regex \b($(join "${keywords}" '|'))\b 0:keyword"
+
+}
+
+# For some reasons this needs to be in its own %sh block
+evaluate-commands %sh{
+ # Generated with `compgen -b` in bash
+ builtins="alias bg bind break builtin caller cd command compgen complete
+ compopt continue declare dirs disown echo enable eval exec
+ exit export false fc fg getopts hash help history jobs kill
+ let local logout mapfile popd printf pushd pwd read readarray
+ readonly return set shift shopt source suspend test times trap
+ true type typeset ulimit umask unalias unset wait"
+
+ join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
+
+ # Add the language's grammar to the static completion list
+ printf %s\\n "set-option -add global sh_static_words $(join "${builtins}" ' ')"
+
+ # Highlight builtins
+ printf %s "add-highlighter shared/sh/code/builtin regex \b($(join "${builtins}" '|'))\b 0:builtin"
}
add-highlighter shared/sh/code/operators regex [\[\]\(\)&|]{1,2} 0:operator
-add-highlighter shared/sh/code/variable regex (\w+)= 1:variable
+add-highlighter shared/sh/code/variable regex (\S+)= 1:variable
add-highlighter shared/sh/code/function regex ^\h*(\w+)\h*\(\) 1:function
add-highlighter shared/sh/code/unscoped_expansion regex \$(\w+|#|@|\?|\$|!|-|\*) 0:value