AutoYADM commit: 2025-05-23 19:15:14

This commit is contained in:
Daniel Fichtinger 2025-05-23 19:15:14 -04:00
parent 29b6990a16
commit 3c31e5303b

View file

@ -16,12 +16,11 @@ hook global BufCreate .*[.](typ|typst) %{
hook global WinSetOption filetype=typst %( hook global WinSetOption filetype=typst %(
require-module typst require-module typst
hook window InsertChar \n -group typst-insert %{ typst-insert-on-newline } hook window ModeChange pop:insert:.* -group typst-trim-indent typst-trim-indent
hook window InsertChar \n -group typst-indent %{ typst-indent-newline } hook window InsertChar .* -group typst-indent typst-indent-on-char
hook window InsertChar \} -group typst-indent %{ typst-indent-closing-brace } hook window InsertChar \n -group typst-indent typst-indent-on-new-line
hook window ModeChange pop:insert:.* -group typst-indent %{ typst-trim-indent }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window typst-indent } hook -once -always window WinSetOption filetype=.* %{ remove-hooks window typst-.+ }
hook window InsertChar \n -group typst-insert typst-insert-on-new-line
) )
hook -group typst-highlight global WinSetOption filetype=typst %{ hook -group typst-highlight global WinSetOption filetype=typst %{
@ -37,55 +36,28 @@ provide-module typst %~
# ------ # ------
define-command -hidden typst-trim-indent %{ define-command -hidden typst-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{ # remove trailing white spaces
try %{ execute-keys x 1s^(\h+)$<ret> d } try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
} }
define-command -hidden typst-insert-on-newline %{ define-command -hidden typst-indent-on-char %<
# copy '//' comment prefix and following white spaces evaluate-commands -draft -itersel %<
try %{ execute-keys -draft kx s^\h*//\h*<ret> y jgh P } # align closer token to its opener when alone on a line
} try %< execute-keys -draft <a-h> <a-k> ^\h+[}])]$ <ret> m <a-S> 1<a-&> >
>
>
define-command -hidden typst-indent-newline %( define-command -hidden typst-indent-on-new-line %<
evaluate-commands -no-hooks -draft -itersel %( evaluate-commands -draft -itersel %<
# preserve previous line indent # preserve previous line indent
try %{ execute-keys -draft K<a-&> } try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line
# remove trailing whitespace on previous line try %{ execute-keys -draft k : typst-trim-indent <ret> }
try %{ execute-keys -draft kx s\h+$<ret> d } # indent after lines ending with opener token
try %< execute-keys -draft k x <a-k> [({[]\h*$ <ret> j <a-gt> >
# indent if previous line ends with "[" # deindent closer token(s) when after cursor
try %( execute-keys -draft kx <a-k>\[$<ret> j<a-gt> ) try %< execute-keys -draft x <a-k> ^\h*[}])] <ret> gh / [}])] <ret> m <a-S> 1<a-&> >
>
# deindent if next line starts with "]" >
try %( execute-keys -draft x <a-k> ^\h*\] <ret> gh / \] <ret> m <a-S> 1<a-&> )
)
)
define-command -hidden typst-indent-closing-brace %(
evaluate-commands -no-hooks -draft -itersel %(
# align closing bracket ] to matching indentation
try %( execute-keys -draft x_ <a-k>^\h*\]\z<ret> m<a-S>1<a-&> )
)
)
define-command -hidden typst-insert-on-new-line %(
evaluate-commands -no-hooks -draft -itersel %(
# Wisely add "\end{...}".
evaluate-commands -save-regs xz %(
# Save previous line indent in register x.
try %( execute-keys -draft kxs^\h+<ret>"xy ) catch %( reg x '' )
# Save item of begin in register z.
try %( execute-keys -draft kxs\{.*\}<ret>"zy ) catch %( reg z '' )
try %(
# Validate previous line and that it is not closed yet.
execute-keys -draft kx <a-k>^<c-r>x\h*\\begin\{.*\}<ret> J}iJx <a-K>^<c-r>x(\\end\<c-r>z<backspace>\})<ret>
# Auto insert "\end{...}".
execute-keys -draft o<c-r>x\end<c-r>z<esc>
)
)
)
)
~ ~