From c6c7fca03f86e355842e8718f31771ee34042d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kruszewski?= Date: Sat, 23 Mar 2024 10:12:36 +0100 Subject: [PATCH] tcl: Add tcl.kak for Tcl highlighting --- rc/filetype/tcl.kak | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 rc/filetype/tcl.kak diff --git a/rc/filetype/tcl.kak b/rc/filetype/tcl.kak new file mode 100644 index 00000000..5823eb57 --- /dev/null +++ b/rc/filetype/tcl.kak @@ -0,0 +1,79 @@ +hook global BufCreate .*[.](tcl) %{ + set-option buffer filetype tcl +} + +hook global WinSetOption filetype=tcl %{ + require-module tcl + + hook window ModeChange pop:insert:.* -group tcl-trim-indent tcl-trim-indent + hook window InsertChar \n -group tcl-insert tcl-insert-on-new-line + hook window InsertChar \n -group tcl-indent tcl-indent-on-new-line + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window tcl-.+ } +} + +hook -group tcl-highlight global WinSetOption filetype=tcl %{ + add-highlighter window/tcl ref tcl + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/tcl } +} + +# Using non-ascii characters here so that we can use the '[' command +provide-module tcl %§ + +add-highlighter shared/tcl regions +add-highlighter shared/tcl/code default-region group +add-highlighter shared/tcl/comment region (? d } +} + +define-command -hidden tcl-insert-on-new-line %[ + # Copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*\K#\h* y gh j P } +] + +define-command -hidden tcl-indent-on-new-line %¶ + evaluate-commands -draft -itersel %@ + # Preserve previous line indent + try %{ execute-keys -draft K } + + # Filter previous line + try %{ execute-keys -draft k : tcl-trim-indent } + + # Indent after { + try %= execute-keys -draft , k x (\s|^)\{$ j = + @ +¶ +§