diff --git a/.config/kak/autoload/fmt.kak b/.config/kak/autoload/fmt.kak index 0fcc1f5f..15b893ae 100644 --- a/.config/kak/autoload/fmt.kak +++ b/.config/kak/autoload/fmt.kak @@ -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^[^\n]{%opt{fmt_width},}[^\n]" + 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\n\n' } + # Insert a newline after selections which close a + # paragraph. + try %{ execute-keys -draft 'L\n\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" - }} + # 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pS\n+\z|sd"cP' + # We use '' (U+E000) to save and restore the cursor + # position after the pipe. + execute-keys 'cpS\n+\z|s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} } } }