diff --git a/rc/filetype/pest.kak b/rc/filetype/pest.kak new file mode 100644 index 0000000000..184d0fe1db --- /dev/null +++ b/rc/filetype/pest.kak @@ -0,0 +1,145 @@ +# https://pest.rs/ + +# Detection +# --------- + +hook global BufCreate .*\.pest %{ + set-option buffer filetype pest +} + +# Initialization +# -------------- + +hook global WinSetOption filetype=pest %{ + require-module pest + + set-option window static_words %opt{pest_static_words} + + hook window ModeChange pop:insert:.* -group pest-trim-indent pest-trim-indent + # apply indentation rules + hook window InsertChar .* -group pest-indent pest-indent-on-char + hook window InsertChar \n -group pest-indent pest-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ try %{ remove-hooks window pest-.+ } } +} + +hook -group pest-highlight global WinSetOption filetype=pest %{ + add-highlighter window/pest ref pest + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/pest } +} + +provide-module pest %∴ + +# Highlighters + +add-highlighter shared/pest regions +add-highlighter shared/pest/code default-region group +# comments +add-highlighter shared/pest/comment region '//' '$' fill comment +add-highlighter shared/pest/comment2 region '/\*' '\*/' fill comment +# string types +add-highlighter shared/pest/string region '"' '(? d } +} + +define-command -hidden pest-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '//' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*//\h* y jgh P } + } +} + +define-command -hidden pest-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to opener when alone on a line + try %< execute-keys -draft ^\h+[\]})]$ m 1 > + > +> + +define-command -hidden pest-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # preserve previous line indent + try %{ exec -draft K } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k :pest-trim-indent } + # indent after lines ending with opener token + try %< execute-keys -draft k x [[{(]\h*$ j > + # deindent closer token(s) when after cursor + try %< execute-keys -draft x ^\h*[}\])] gh / [}\])] m 1 > + > +> + +∴ diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 0c1341121b..4fe05ebb68 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -16,7 +16,7 @@ hook global BufSetOption filetype=asciidoc %{ set-option buffer comment_block_end '////' } -hook global BufSetOption filetype=(c|cpp|dart|gluon|go|hjson|java|javascript|json5|kdl|objc|odin|php|pony|protobuf|ron|rust|sass|scala|scss|swift|typescript|typst|groovy) %{ +hook global BufSetOption filetype=(c|cpp|dart|gluon|go|hjson|java|javascript|json5|kdl|objc|odin|pest|php|pony|protobuf|ron|rust|sass|scala|scss|swift|typescript|typst|groovy) %{ set-option buffer comment_line '//' set-option buffer comment_block_begin '/*' set-option buffer comment_block_end '*/'