From 9ac6669e5081e095ee7532210bf3379f553de4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez?= Date: Wed, 16 Mar 2022 21:55:44 -0500 Subject: [PATCH] basic support for twig --- rc/filetype/twig.kak | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 rc/filetype/twig.kak diff --git a/rc/filetype/twig.kak b/rc/filetype/twig.kak new file mode 100644 index 00000000..21f8cebc --- /dev/null +++ b/rc/filetype/twig.kak @@ -0,0 +1,95 @@ +# 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-grater-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 k^\h*\{\[%#\{\]\h+$ + execute-keys -draft jghd + ] + / +] + +]