2016-07-08 12:50:47 +02:00
|
|
|
# Maximum amount of characters per line
|
2015-07-24 15:00:29 +02:00
|
|
|
decl int autowrap_column 80
|
|
|
|
|
2016-07-08 12:50:47 +02:00
|
|
|
# If enabled, paragraph formatting will reformat the whole paragraph in which characters are being inserted
|
|
|
|
# This can potentially break formatting of documents containing markup (e.g. markdown)
|
2016-07-14 16:32:56 +02:00
|
|
|
decl bool autowrap_format_paragraph no
|
2016-07-08 12:50:47 +02:00
|
|
|
# Command to which the paragraphs to wrap will be passed, all occurences of '%c' are replaced with `autowrap_column`
|
2016-07-08 17:02:39 +02:00
|
|
|
decl str autowrap_fmtcmd 'fold -s -w %c'
|
2015-09-16 10:58:47 +02:00
|
|
|
|
2016-07-14 15:40:08 +02:00
|
|
|
def -hidden autowrap-cursor %{ eval -save-regs '/"|^@m' %{
|
2015-09-16 10:58:47 +02:00
|
|
|
try %{
|
2016-07-08 12:50:47 +02:00
|
|
|
## if the line isn't too long, do nothing
|
2016-07-14 15:40:08 +02:00
|
|
|
exec -draft "<a-x><a-k>^[^\n]{%opt{autowrap_column},}[^\n]<ret>"
|
2016-07-08 12:50:47 +02:00
|
|
|
|
2016-03-13 08:47:17 +01:00
|
|
|
try %{
|
2016-07-14 15:40:08 +02:00
|
|
|
reg m "%val{selections_desc}"
|
|
|
|
|
2016-07-08 12:50:47 +02:00
|
|
|
## if we're adding characters past the limit, just wrap them around
|
2016-07-14 16:21:35 +02:00
|
|
|
exec -draft "<a-h><a-k>.{%opt{autowrap_column}}\h*[^\s]*<ret>1s(\h+)[^\h]*\'<ret>c<ret><esc>"
|
2016-07-08 12:50:47 +02:00
|
|
|
} catch %{
|
|
|
|
## if we're adding characters in the middle of a sentence, use
|
|
|
|
## the `fmtcmd` command to wrap the entire paragraph
|
|
|
|
%sh{
|
|
|
|
if [[ "${kak_opt_autowrap_format_paragraph}" = true ]] \
|
|
|
|
&& [[ -n "${kak_opt_autowrap_fmtcmd}" ]]; then
|
|
|
|
format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \
|
2016-07-14 15:40:08 +02:00
|
|
|
| sed "s/%c/${kak_opt_autowrap_column}/g")
|
|
|
|
printf %s "
|
2016-07-14 16:32:56 +02:00
|
|
|
exec '<a-]>p<a-x><a-j>|${format_cmd}<ret>'
|
2016-07-14 15:40:08 +02:00
|
|
|
try %{ exec s\h+$<ret> d }
|
|
|
|
select '${kak_reg_m}'
|
|
|
|
"
|
2016-07-08 12:50:47 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
2015-07-29 10:48:07 +02:00
|
|
|
}
|
2016-03-13 08:47:17 +01:00
|
|
|
} }
|
2015-07-29 10:48:07 +02:00
|
|
|
|
2015-08-03 20:44:27 +02:00
|
|
|
def autowrap-enable -docstring "Wrap the lines in which characters are inserted" %{
|
2016-07-08 12:50:47 +02:00
|
|
|
hook -group autowrap window InsertChar [^\n] autowrap-cursor
|
2015-07-24 15:00:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 20:44:27 +02:00
|
|
|
def autowrap-disable -docstring "Disable automatic line wrapping" %{
|
2015-07-24 15:00:29 +02:00
|
|
|
rmhooks window autowrap
|
|
|
|
}
|