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/pug.kak | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 autoload/filetype/pug.kak (limited to 'autoload/filetype/pug.kak') diff --git a/autoload/filetype/pug.kak b/autoload/filetype/pug.kak new file mode 100644 index 0000000..db05c9b --- /dev/null +++ b/autoload/filetype/pug.kak @@ -0,0 +1,81 @@ +# Note: jade is changing its name to pug (https://github.com/pugjs/pug/issues/2184) +# This appears to be a work in progress -- the pug-lang domain is parked, while +# the jade-lang one is active. This highlighter will recognize .pug and .jade extensions, + +# http://jade-lang.com (will be http://pug-lang.com) +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](pug|jade) %{ + set-option buffer filetype pug +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=pug %{ + require-module pug + + hook window ModeChange pop:insert:.* -group pug-trim-indent pug-trim-indent + hook window InsertChar \n -group pug-indent pug-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pug-.+ } +} + +hook -group pug-highlight global WinSetOption filetype=pug %{ + add-highlighter window/pug ref pug + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pug } +} + + +provide-module pug %{ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/pug regions +add-highlighter shared/pug/code default-region group +add-highlighter shared/pug/text region ^\h*\|\s $ regex \h*(\|) 1:meta +add-highlighter shared/pug/text2 region '^\h*([A-Za-z][A-Za-z0-9_-]*)?(#[A-Za-z][A-Za-z0-9_-]*)?((?:\.[A-Za-z][A-Za-z0-9_-]*)*)?(? d } +} + +define-command -hidden pug-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 : pug-trim-indent } + # copy '//', '|', '-' or '(!)=' prefix and following whitespace + try %{ execute-keys -draft k x s ^\h*\K[/|!=-]{1,2}\h* y gh j P } + # indent unless we copied something above + try %{ execute-keys -draft , b s \S g l } + } +} + +} -- cgit v1.2.3