summaryrefslogtreecommitdiff
path: root/rc/filetype/just.kak
diff options
context:
space:
mode:
authorAlex Leferry 2 <alexherbo2@gmail.com>2019-03-18 19:56:34 +0100
committerAlex Leferry 2 <alexherbo2@gmail.com>2019-03-21 01:06:16 +0100
commitc0dccdd90dd615cf663d95fd94fbdbdf2a88b165 (patch)
treecb48fb1b7fb74e6e3b98a62f6e2768686bb75c98 /rc/filetype/just.kak
parentf87e844244d5ee81e9c1ceb04c354726002ae760 (diff)
Add categories in rc/
Closes #2783
Diffstat (limited to 'rc/filetype/just.kak')
-rw-r--r--rc/filetype/just.kak48
1 files changed, 48 insertions, 0 deletions
diff --git a/rc/filetype/just.kak b/rc/filetype/just.kak
new file mode 100644
index 00000000..201bfc3d
--- /dev/null
+++ b/rc/filetype/just.kak
@@ -0,0 +1,48 @@
+# Detection
+# ‾‾‾‾‾‾‾‾‾
+
+hook global BufCreate .*/?[jJ]ustfile %{
+ set-option buffer filetype justfile
+}
+
+# Indentation
+# ‾‾‾‾‾‾‾‾‾‾‾
+
+define-command -hidden just-indent-on-new-line %{
+ evaluate-commands -draft -itersel %{
+ # preserve previous line indent
+ try %{ execute-keys -draft \;K<a-&> }
+ # cleanup trailing white spaces on previous line
+ try %{ execute-keys -draft k<a-x> s \h+$ <ret>"_d }
+ # copy '#' comment prefix and following white spaces
+ try %{ execute-keys -draft k <a-x> s ^\h*//\h* <ret> y jgh P }
+ }
+}
+
+# Highlighters
+# ‾‾‾‾‾‾‾‾‾‾‾‾
+
+add-highlighter shared/justfile regions
+add-highlighter shared/justfile/content default-region group
+add-highlighter shared/justfile/comment region '#' '$' fill comment
+add-highlighter shared/justfile/double_string region '"' (?<!\\)(\\\\)*" fill string
+add-highlighter shared/justfile/single_string region "'" (?<!\\)(\\\\)*' fill string
+add-highlighter shared/justfile/inline region '`' '`' ref sh
+
+add-highlighter shared/justfile/shell region '^\h+' '^[^\h]' group
+add-highlighter shared/justfile/shell/ ref sh
+add-highlighter shared/justfile/shell/ regex '(\{{2})([\w-]+)(\}{2})' 1:operator 2:variable 3:operator
+
+add-highlighter shared/justfile/content/ regex '^(@)?([\w-]+)(?:\s(.+))?\s?(:)(.+)?$' 1:operator 2:function 3:value 4:operator 5:type
+add-highlighter shared/justfile/content/ regex '([=+])' 1:operator
+add-highlighter shared/justfile/content/ regex '^([\w-]+)\s=' 1:value
+
+hook -group justfile-highlight global WinSetOption filetype=justfile %{
+ add-highlighter window/justfile ref justfile
+ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/justfile }
+}
+
+hook global WinSetOption filetype=justfile %{
+ hook window InsertChar \n -group justfile-indent just-indent-on-new-line
+ hook -once -always window WinSetOption filetype=.* %{ remove-hooks window justfile-.+ }
+}