2015-09-21 14:37:45 +02:00
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2019-10-25 14:14:30 +02:00
|
|
|
hook global BufCreate .*(/?[mM]akefile|\.mk|\.make) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype makefile
|
2015-09-21 14:37:45 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 05:54:19 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=makefile %{
|
2019-03-13 06:24:33 +01:00
|
|
|
require-module makefile
|
2019-04-10 05:54:19 +02:00
|
|
|
|
|
|
|
set-option window static_words %opt{makefile_static_words}
|
|
|
|
|
2022-05-08 15:01:25 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group makefile-trim-indent makefile-trim-indent
|
2019-04-10 05:54:19 +02:00
|
|
|
hook window InsertChar \n -group makefile-indent makefile-indent-on-new-line
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window makefile-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group makefile-highlight global WinSetOption filetype=makefile %{
|
|
|
|
add-highlighter window/makefile ref makefile
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/makefile }
|
2019-03-13 06:24:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
provide-module makefile %{
|
|
|
|
|
2015-09-21 14:37:45 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-06-28 13:08:58 +02:00
|
|
|
add-highlighter shared/makefile regions
|
2015-09-21 14:37:45 +02:00
|
|
|
|
2018-06-28 13:08:58 +02:00
|
|
|
add-highlighter shared/makefile/content default-region group
|
2020-07-18 23:18:07 +02:00
|
|
|
add-highlighter shared/makefile/comment region (?<!\\)(?:\\\\)*(?:^|\h)\K# '$' fill comment
|
2020-09-05 07:36:31 +02:00
|
|
|
add-highlighter shared/makefile/evaluate-commands region -recurse \( (?<!\$)(?:\$\$)*\K\$\( \) fill value
|
2015-09-21 14:37:45 +02:00
|
|
|
|
2019-07-30 14:43:11 +02:00
|
|
|
add-highlighter shared/makefile/content/ regex ^\S.*?(::|:|!)\s 0:variable
|
2018-06-28 13:08:58 +02:00
|
|
|
add-highlighter shared/makefile/content/ regex [+?:]= 0:operator
|
2015-09-21 14:37:45 +02:00
|
|
|
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %sh{
|
2016-03-14 13:08:51 +01:00
|
|
|
# Grammar
|
2016-09-24 10:09:42 +02:00
|
|
|
keywords="ifeq|ifneq|ifdef|ifndef|else|endif|define|endef"
|
2016-03-14 13:08:51 +01:00
|
|
|
|
|
|
|
# Add the language's grammar to the static completion list
|
2019-04-10 05:54:19 +02:00
|
|
|
printf %s\\n "declare-option str-list makefile_static_words ${keywords}" | tr '|' ' '
|
2016-03-14 13:08:51 +01:00
|
|
|
|
|
|
|
# Highlight keywords
|
2018-06-30 01:49:57 +02:00
|
|
|
printf %s "add-highlighter shared/makefile/content/ regex \b(${keywords})\b 0:keyword"
|
2016-03-14 13:08:51 +01:00
|
|
|
}
|
|
|
|
|
2016-02-24 23:26:54 +01:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2022-05-08 15:01:25 +02:00
|
|
|
define-command -hidden makefile-trim-indent %{
|
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2022-03-16 23:20:07 +01:00
|
|
|
execute-keys x
|
2022-05-08 15:01:25 +02:00
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ execute-keys -draft s \h + $ <ret> d }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden makefile-indent-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2016-02-24 23:26:54 +01:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon>K<a-&> }
|
2016-02-24 23:26:54 +01:00
|
|
|
## If the line above is a target indent with a tab
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft Z kx <a-k>^\S.*?(::|:|!)\s<ret> z i<tab> }
|
2016-02-24 23:26:54 +01:00
|
|
|
# cleanup trailing white space son previous line
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft kx s \h+$ <ret>d }
|
2016-09-25 08:19:04 +02:00
|
|
|
# indent after some keywords
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft Z kx <a-k> ^\h*(ifeq|ifneq|ifdef|ifndef|else|define)\b<ret> z <a-gt> }
|
2016-02-24 23:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 06:24:33 +01:00
|
|
|
}
|