AutoYADM commit: 2025-06-24 20:30:05

This commit is contained in:
Daniel Fichtinger 2025-06-24 20:30:05 -04:00
parent 6d4c81fc68
commit 2bbd2e7fc1

View file

@ -1,7 +1,6 @@
declare-option -hidden str fmt_command %{
fmt -u | perl -CS -pe 's/([.!?])\s{2,}/\1 /g'
# original:
# fmt --uniform-spacing "--goal=$kak_opt_fmt_width" "--width=$kak_opt_fmt_width" | sed "s/\. /. /g"
# fmt --uniform-spacing "--goal=$kak_opt_fmt_width" "--width=$kak_opt_fmt_width" | perl -CS -pe 's/([.!?])\s{2,}/\1 /g'
fmt -u -w "$kak_opt_fmt_width" | perl -CS -pe 's/([.!?])\s{2,}/\1 /g'
}
declare-option -hidden str fmt_mode fail
@ -27,32 +26,36 @@ define-command -docstring "enable autofmt at window scope" fmt-enable-window %{
}
define-command -hidden fmt-impl-window %{
evaluate-commands -save-regs "c|s" %{
evaluate-commands -draft %{
execute-keys ';'
try %{
# do nothing if the line isn't too long
execute-keys -draft "x<a-k>^[^\n]{%opt{fmt_width},}[^\n]<ret>"
evaluate-commands -save-regs "c|s" %{
evaluate-commands -draft %{
execute-keys ';'
# Insert a newline after selections which close a
# paragraph.
try %{ execute-keys -draft 'L<a-k>\n\n<ret><a-o>' }
# Insert a newline after selections which close a
# paragraph.
try %{ execute-keys -draft 'L<a-k>\n\n<ret><a-o>' }
# If we were to yank newlines and paste them in the below
# 'execute-keys', we would end up typing in reverse,
# as the newline would be repeatedly pasted and removed
# before the typed content. So, we remove them.
evaluate-commands %exp{ set-register c %sh{
printf %s "$kak_quoted_selections" | tr -d "\n"
}}
# If we were to yank newlines and paste them in the below
# 'execute-keys', we would end up typing in reverse,
# as the newline would be repeatedly pasted and removed
# before the typed content. So, we remove them.
evaluate-commands %exp{ set-register c %sh{
printf %s "$kak_quoted_selections" | tr -d "\n"
}}
set-register | %opt{fmt_command}
set-register | %opt{fmt_command}
# We use '' (U+E000) to save and restore the cursor
# position after the pipe.
execute-keys 'c<esc><a-i>p<a-j>S\n+\z<ret>|<ret>s<ret>d"cP'
# We use '' (U+E000) to save and restore the cursor
# position after the pipe.
execute-keys 'c<esc><a-i>p<a-j>S\n+\z<ret>|<ret>s<ret>d"cP'
set-register s "%val{selections_desc}"
set-register s "%val{selections_desc}"
}
evaluate-commands %exp{ select %reg{s} }
}
evaluate-commands %exp{ select %reg{s} }
}
}