Fix paragraph wrapping in the autowrap script

This commit is contained in:
Frank LENORMAND 2016-07-14 16:40:08 +03:00
parent 52d3b60aaa
commit ba3c7bab06

View File

@ -7,14 +7,16 @@ decl bool autowrap_format_paragraph yes
# Command to which the paragraphs to wrap will be passed, all occurences of '%c' are replaced with `autowrap_column` # Command to which the paragraphs to wrap will be passed, all occurences of '%c' are replaced with `autowrap_column`
decl str autowrap_fmtcmd 'fold -s -w %c' decl str autowrap_fmtcmd 'fold -s -w %c'
def -hidden autowrap-cursor %{ eval -draft %{ def -hidden autowrap-cursor %{ eval -save-regs '/"|^@m' %{
try %{ try %{
## if the line isn't too long, do nothing ## if the line isn't too long, do nothing
exec -draft "<a-x><a-k>^[^\n]{%opt{autowrap_column},}<ret>" exec -draft "<a-x><a-k>^[^\n]{%opt{autowrap_column},}[^\n]<ret>"
try %{ try %{
reg m "%val{selections_desc}"
## if we're adding characters past the limit, just wrap them around ## if we're adding characters past the limit, just wrap them around
exec "<a-h><a-k>.{%opt{autowrap_column},}<ret>1s(\h+)[^\h]+\'<ret>c<ret><esc>" exec "<a-h><a-k>.{%opt{autowrap_column},}\h*[^\s]<ret>1s.{%opt{autowrap_column}}[^\h]*(\h+)<ret>c<ret><esc>"
} catch %{ } catch %{
## if we're adding characters in the middle of a sentence, use ## if we're adding characters in the middle of a sentence, use
## the `fmtcmd` command to wrap the entire paragraph ## the `fmtcmd` command to wrap the entire paragraph
@ -22,9 +24,12 @@ def -hidden autowrap-cursor %{ eval -draft %{
if [[ "${kak_opt_autowrap_format_paragraph}" = true ]] \ if [[ "${kak_opt_autowrap_format_paragraph}" = true ]] \
&& [[ -n "${kak_opt_autowrap_fmtcmd}" ]]; then && [[ -n "${kak_opt_autowrap_fmtcmd}" ]]; then
format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \ format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \
| sed -e "s/%c/${kak_opt_autowrap_column}/g" \ | sed "s/%c/${kak_opt_autowrap_column}/g")
-e 's/ /<space>/g') printf %s "
printf %s "exec -draft <a-i>p|${format_cmd}<ret>" exec '<a-]>p<a-x>|${format_cmd}<ret>'
try %{ exec s\h+$<ret> d }
select '${kak_reg_m}'
"
fi fi
} }
} }