Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions rc/tools/autowrap.kak
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m'
execute-keys -draft "x<a-k>^[^\n]{%opt{autowrap_column},}[^\n]<ret>"

try %{
reg m "%val{selections_desc}"

## if we're adding characters past the limit, just wrap them around
execute-keys -draft "<a-h><a-k>.{%opt{autowrap_column}}\h*[^\s]*<ret>1s(\h+)[^\h]*\z<ret>c<ret>"
} catch %{
## if we're adding characters in the middle of a sentence, use
## the `fmtcmd` command to wrap the entire paragraph
evaluate-commands %sh{
if [ "${kak_opt_autowrap_format_paragraph}" = true ] \
&& [ -n "${kak_opt_autowrap_fmtcmd}" ]; then
format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \
| sed "s/%c/${kak_opt_autowrap_column}/g")
printf %s "
evaluate-commands -draft %{
execute-keys '<a-]>px<a-j>|${format_cmd}<ret>'
try %{ execute-keys s\h+$<ret> d }
}
select '${kak_main_reg_m}'
"
fi
}
}

reg m "%val{selections_desc}"
## if we're adding characters in the middle of a sentence, use
## the `fmtcmd` command to wrap the entire paragraph
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems out of date now, AFAIU this change runs the format command regardless of if we are adding character at the end or in the middle of the sentence as we do not only run in the case where the previous execute-keys failed anymore.

evaluate-commands %sh{
if [ "${kak_opt_autowrap_format_paragraph}" = true ] \
&& [ -n "${kak_opt_autowrap_fmtcmd}" ]; then
format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \
| sed "s/%c/${kak_opt_autowrap_column}/g")
printf %s "
evaluate-commands -draft %{
execute-keys '<a-]>px<a-j>|${format_cmd}<ret>'
try %{ execute-keys s\h+$<ret> d }
}
select '${kak_main_reg_m}'
"
fi
}
}
} }

define-command autowrap-enable -docstring "Automatically wrap the lines in which characters are inserted" %{
hook -group autowrap window InsertChar [^\n] autowrap-cursor
hook -group autowrap window InsertChar '[^\n ]' autowrap-cursor
}

define-command autowrap-disable -docstring "Disable automatic line wrapping" %{
Expand Down