39 lines
1.5 KiB
Text
39 lines
1.5 KiB
Text
declare-user-mode paragraph
|
|
declare-option -hidden str paragraph_select '<a-a>pj[p'
|
|
|
|
declare-option -hidden str reflow_cmd %{
|
|
fmt -u | perl -CS -pe 's/([.!?])\s{2,}/\1 /g'
|
|
}
|
|
|
|
define-command format-paragraph %{
|
|
execute-keys -draft <a-a>p_x:<space>format-selections<ret>
|
|
}
|
|
|
|
define-command -override -params 0..1 reflow-paragraph %{
|
|
evaluate-commands -draft -save-regs 'a|' %{
|
|
set-register | %opt{reflow_cmd}
|
|
set-register a %sh{
|
|
if [ "$#" = 0 ]; then
|
|
printf '%s' '|<ret>'
|
|
else
|
|
printf '%s' ':<space>format-selections<ret>'
|
|
fi
|
|
}
|
|
echo -debug %reg{a}
|
|
execute-keys -draft '<a-a>p_x:exec <c-r>a<ret>'
|
|
}
|
|
}
|
|
|
|
map global normal <a-ret> ': reflow-paragraph<ret>'
|
|
map global normal <ret> '<a-a>pj[p<a-;>'
|
|
map global normal <s-ret> ': reflow-paragraph formatcmd<ret>'
|
|
map -docstring 'paragraph mode' global user <ret> "%opt{paragraph_select}: enter-user-mode -lock paragraph<ret>"
|
|
map global paragraph I '>' -docstring 'move right'
|
|
map global paragraph M '<' -docstring 'move left'
|
|
map global paragraph E "d[pP[p%opt{paragraph_select}" -docstring 'move up'
|
|
map global paragraph N "d]pp]p[p%opt{paragraph_select}" -docstring 'move down'
|
|
map global paragraph n "]p%opt{paragraph_select}" -docstring 'select down'
|
|
map global paragraph e "[p%opt{paragraph_select}" -docstring 'select up'
|
|
map global paragraph d "d%opt{paragraph_select}" -docstring 'delete'
|
|
map global paragraph y y -docstring 'yank'
|
|
|