AutoYADM commit: 2025-07-09 13:06:20

This commit is contained in:
Daniel Fichtinger 2025-07-09 13:06:20 -04:00
parent 2c49e5ee47
commit 0947338afb

View file

@ -1,26 +1,15 @@
declare-option str markdown_formatcmd %{
if dprint output-resolved-config >/dev/null 2>&1; then
dprint fmt --stdin md
else
dprint fmt --stdin md --config "$HOME/.dprint.jsonc"
fi
}
define-command markdown-fmt-impl %{
evaluate-commands -draft -save-regs "fbs/l" %{
set-register b %reg{percent}
execute-keys -draft '%"fy'
edit -scratch
execute-keys '"fR'
set-register s %reg{percent}
# format markdown, ignoring block images!
define-command markdown-fmt %{
evaluate-commands -draft -save-regs "/l" %{
# block level images regex
set-register / '(?S)^\h*!\[.*\]\(.*\)$'
execute-keys '%s<ret>"lyc<lt>!--𝅙--<gt><esc>'
set-register | %opt{markdown_formatcmd}
execute-keys '%|<ret>'
set-register / '(?S)^\h*<!--𝅙-->'
execute-keys '%s<ret>"lR%"fy'
buffer %reg{b}
delete-buffer %reg{s}
execute-keys '%"fR'
# select, yank, replace with comment
execute-keys '%s<ret>"lyc<lt>!--img𝅙img--<gt><esc>'
# pass to formatter
format
# select the comments, replace with original image
set-register / '(?S)^\h*<!--img𝅙img-->'
execute-keys '%s<ret>"lR'
}
}
@ -38,8 +27,8 @@ hook global WinSetOption filetype=markdown %{
dprint fmt --stdin md --config "$HOME/.dprint.jsonc"
fi
}
hook -group markdown-auto-format window BufWritePre .* { markdown-fmt-impl }
map window normal = ': markdown-fmt-impl<ret>'
hook -group markdown-auto-format window BufWritePre .* %{ markdown-fmt }
map window normal = ': markdown-fmt<ret>'
# override formatting commands
define-command -override -hidden markdown-trim-indent %{