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)
|
|
|
|
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`
|
|
|
|
decl str autowrap_fmtcmd 'fmt -s -w %c'
|
2015-09-16 10:58:47 +02:00
|
|
|
|
2016-07-08 12:50:47 +02:00
|
|
|
def -hidden autowrap-cursor %{ eval -draft %{
|
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
|
|
|
|
exec -draft "<a-x><a-k>^[^\n]{%opt{autowrap_column},}<ret>"
|
|
|
|
|
2016-03-13 08:47:17 +01:00
|
|
|
try %{
|
2016-07-08 12:50:47 +02:00
|
|
|
## 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>"
|
|
|
|
} 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}" \
|
|
|
|
| sed -e "s/%c/${kak_opt_autowrap_column}/g" \
|
|
|
|
-e 's/ /<space>/g')
|
|
|
|
printf %s "exec -draft <a-i>p|${format_cmd}<ret>"
|
|
|
|
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
|
|
|
|
}
|