AutoYADM commit: 2025-05-13 00:55:12

This commit is contained in:
Daniel Fichtinger 2025-05-13 00:55:12 -04:00
parent 3a00aaeae6
commit b4b4592c06

View file

@ -0,0 +1,90 @@
# https://www.latex-project.org/
#
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](typ|typst) %{
set-option buffer filetype typst
set-option buffer formatcmd "typstyle --wrap-text"
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=typst %(
require-module typst
hook window InsertChar \n -group typst-insert %{ typst-insert-on-newline }
hook window InsertChar \n -group typst-indent %{ typst-indent-newline }
hook window InsertChar \} -group typst-indent %{ typst-indent-closing-brace }
hook window ModeChange pop:insert:.* -group typst-indent %{ typst-trim-indent }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window typst-indent }
hook window InsertChar \n -group typst-insert typst-insert-on-new-line
)
hook -group typst-highlight global WinSetOption filetype=typst %{
add-highlighter window/typst ref typst
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/typst }
}
provide-module typst %~
# not setting highlights b/c it's handled by treesitter
# Indent
# ------
define-command -hidden typst-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
try %{ execute-keys x 1s^(\h+)$<ret> d }
}
}
define-command -hidden typst-insert-on-newline %{
# copy '//' comment prefix and following white spaces
try %{ execute-keys -draft kx s^\h*//\h*<ret> y jgh P }
}
define-command -hidden typst-indent-newline %(
evaluate-commands -no-hooks -draft -itersel %(
# preserve previous line indent
try %{ execute-keys -draft K<a-&> }
# remove trailing whitespace on previous line
try %{ execute-keys -draft kx s\h+$<ret> d }
# indent if previous line ends with "["
try %( execute-keys -draft kx <a-k>\[$<ret> j<a-gt> )
# 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>
)
)
)
)
~