From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/twig.kak | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 autoload/filetype/twig.kak (limited to 'autoload/filetype/twig.kak') diff --git a/autoload/filetype/twig.kak b/autoload/filetype/twig.kak new file mode 100644 index 0000000..2f5ef18 --- /dev/null +++ b/autoload/filetype/twig.kak @@ -0,0 +1,89 @@ +# https://twig.symfony.com/doc/3.x/templates.html +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](twig) %{ + set-option buffer filetype twig +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=twig %[ + require-module twig + + hook window ModeChange pop:insert:.* -group twig-trim-indent twig-trim-indent + hook window InsertChar \n -group twig-insert twig-insert-on-new-line + hook window InsertChar \n -group twig-indent twig-indent-on-new-line + hook window InsertChar '>' -group twig-indent twig-indent-on-greater-than + hook window InsertChar '#' -group twig-auto-close twig-auto-close-delim + hook window InsertChar '%' -group twig-auto-close twig-auto-close-delim + set-option buffer extra_word_chars '_' '-' + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window twig-.+ } +] + +hook -group twig-highlight global WinSetOption filetype=twig %{ + add-highlighter window/twig ref twig + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/twig } +} + + +provide-module twig %[ + +require-module html + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/twig regions +add-highlighter shared/twig/core default-region group +add-highlighter shared/twig/comment region \{# [#]\} fill comment +add-highlighter shared/twig/delim region \{([%]-?|\{) (-?[%]|\})\} regions + +add-highlighter shared/twig/core/ ref html + +add-highlighter shared/twig/delim/base default-region group +add-highlighter shared/twig/delim/double_string region '"' (?hH\h*\{lyp + execute-keys hihi + ] + ] +] + +define-command -hidden twig-insert-on-new-line %[ + evaluate-commands -draft -itersel %/ + execute-keys + try %[ + execute-keys -draft kx^\h*\{\[%#\{\]\h+$ + execute-keys -draft jghd + ] + / +] + +] -- cgit v1.2.3