summaryrefslogtreecommitdiff
path: root/rc/filetype/makefile.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/makefile.kak
parentf87e844244d5ee81e9c1ceb04c354726002ae760 (diff)
Add categories in rc/
Closes #2783
Diffstat (limited to 'rc/filetype/makefile.kak')
-rw-r--r--rc/filetype/makefile.kak60
1 files changed, 60 insertions, 0 deletions
diff --git a/rc/filetype/makefile.kak b/rc/filetype/makefile.kak
new file mode 100644
index 00000000..569d51f9
--- /dev/null
+++ b/rc/filetype/makefile.kak
@@ -0,0 +1,60 @@
+# Detection
+# ‾‾‾‾‾‾‾‾‾
+
+hook global BufCreate .*(/?[mM]akefile|\.mk) %{
+ set-option buffer filetype makefile
+}
+
+# Highlighters
+# ‾‾‾‾‾‾‾‾‾‾‾‾
+
+add-highlighter shared/makefile regions
+
+add-highlighter shared/makefile/content default-region group
+add-highlighter shared/makefile/comment region '#' '$' fill comment
+add-highlighter shared/makefile/evaluate-commands region -recurse '\(' '\$\(' '\)' fill value
+
+add-highlighter shared/makefile/content/ regex ^[\w.%-]+\h*:\s 0:variable
+add-highlighter shared/makefile/content/ regex [+?:]= 0:operator
+
+evaluate-commands %sh{
+ # Grammar
+ keywords="ifeq|ifneq|ifdef|ifndef|else|endif|define|endef"
+
+ # Add the language's grammar to the static completion list
+ printf %s\\n "hook global WinSetOption filetype=makefile %{
+ set-option window static_words ${keywords}
+ }" | tr '|' ' '
+
+ # Highlight keywords
+ printf %s "add-highlighter shared/makefile/content/ regex \b(${keywords})\b 0:keyword"
+}
+
+# Commands
+# ‾‾‾‾‾‾‾‾
+
+define-command -hidden makefile-indent-on-new-line %{
+ evaluate-commands -draft -itersel %{
+ # preserve previous line indent
+ try %{ execute-keys -draft \;K<a-&> }
+ ## If the line above is a target indent with a tab
+ try %{ execute-keys -draft Z k<a-x> <a-k>^[^:]+:\s<ret> z i<tab> }
+ # cleanup trailing white space son previous line
+ try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
+ # indent after some keywords
+ try %{ execute-keys -draft Z k<a-x> <a-k> ^\h*(ifeq|ifneq|ifdef|ifndef|else|define)\b<ret> z <a-gt> }
+ }
+}
+
+# Initialization
+# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+
+hook -group makefile-highlight global WinSetOption filetype=makefile %{
+ add-highlighter window/makefile ref makefile
+ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/makefile }
+}
+
+hook global WinSetOption filetype=makefile %{
+ hook window InsertChar \n -group makefile-indent makefile-indent-on-new-line
+ hook -once -always window WinSetOption filetype=.* %{ remove-hooks window makefile-.+ }
+}