AutoYADM commit: 2025-06-24 20:15:00
This commit is contained in:
parent
a1faa7d872
commit
6d4c81fc68
2 changed files with 78 additions and 7 deletions
71
.config/kak/autoload/fmt.kak
Normal file
71
.config/kak/autoload/fmt.kak
Normal file
|
@ -0,0 +1,71 @@
|
|||
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"
|
||||
}
|
||||
|
||||
declare-option -hidden str fmt_mode fail
|
||||
declare-option int fmt_width 80
|
||||
|
||||
define-command -docstring "run fmt for each selection" fmt %{
|
||||
evaluate-commands -save-regs | %{
|
||||
set-register | %opt{fmt_command}
|
||||
execute-keys -itersel '|<ret>'
|
||||
}
|
||||
}
|
||||
|
||||
define-command -docstring "disable autofmt at window scope" fmt-disable-window %{
|
||||
set-option window fmt_mode fail
|
||||
trigger-user-hook fmt-disable-window
|
||||
remove-hooks window fmt
|
||||
}
|
||||
|
||||
define-command -docstring "enable autofmt at window scope" fmt-enable-window %{
|
||||
set-option window fmt_mode nop
|
||||
trigger-user-hook fmt-enable-window
|
||||
hook -group fmt window InsertChar [^\s] fmt-impl-window
|
||||
}
|
||||
|
||||
define-command -hidden fmt-impl-window %{
|
||||
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>' }
|
||||
|
||||
# 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}
|
||||
|
||||
# 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}"
|
||||
}
|
||||
|
||||
evaluate-commands %exp{ select %reg{s} }
|
||||
}
|
||||
}
|
||||
|
||||
define-command -docstring "toggle autofmt at window scope" fmt-toggle-window %{
|
||||
try %{
|
||||
eval %opt{fmt_mode}
|
||||
fmt-disable-window
|
||||
} catch %{
|
||||
fmt-enable-window
|
||||
}
|
||||
}
|
||||
|
||||
declare-option str fmt_info
|
||||
hook global User fmt-enable-window %{ set-option window fmt_info "fmt " }
|
||||
hook global User fmt-disable-window %{ set-option window fmt_info "" }
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue