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