2015-07-29 11:48:07 +03:00
|
|
|
## Maximum amount of characters per line
|
2015-07-24 16:00:29 +03:00
|
|
|
decl int autowrap_column 80
|
|
|
|
|
2016-03-13 10:47:17 +03:00
|
|
|
# remove the whitespaces selected by `autowrap-line`
|
|
|
|
# and handle "recursive" calls when needed
|
|
|
|
def -hidden _autowrap-cut-selection %{
|
2015-07-29 11:48:07 +03:00
|
|
|
try %{
|
2016-03-13 10:47:17 +03:00
|
|
|
# remove the whitespaces
|
|
|
|
# then save the indentation of the original line and apply it to the new one
|
2016-03-14 10:15:47 +03:00
|
|
|
exec -draft c<ret><esc> K <a-&>
|
2016-03-13 10:47:17 +03:00
|
|
|
# if there's text after the current line, merge the two
|
|
|
|
exec xX <a-k>[^\n]\n[^\n]<ret> <a-j>
|
2015-09-16 11:58:47 +03:00
|
|
|
}
|
2016-03-13 10:47:17 +03:00
|
|
|
eval autowrap-line
|
2015-09-16 11:58:47 +03:00
|
|
|
}
|
|
|
|
|
2016-03-13 10:47:17 +03:00
|
|
|
def autowrap-line -docstring "Wrap the current line" %{ eval -draft %{
|
2015-09-16 11:58:47 +03:00
|
|
|
try %{
|
2016-03-13 10:47:17 +03:00
|
|
|
# check that the line is too long and has to be wrapped
|
|
|
|
exec "<a-x> s^(?=.*\h).{%opt{autowrap_column}}[^\n]<ret>"
|
|
|
|
try %{
|
|
|
|
# either select the trailing whitespaces, or the ones before the last word of the line
|
|
|
|
exec s\h+(?=[^\h]+\')|\h+\'<ret>
|
|
|
|
eval _autowrap-cut-selection
|
|
|
|
} catch %{ try %{
|
|
|
|
# wrap the line on the first whitespace that's past the column limit
|
|
|
|
exec "x s^[^\h]{%opt{autowrap_column},}\K\h+<ret>"
|
|
|
|
eval _autowrap-cut-selection
|
|
|
|
} }
|
2015-07-29 11:48:07 +03:00
|
|
|
}
|
2016-03-13 10:47:17 +03:00
|
|
|
} }
|
2015-07-29 11:48:07 +03:00
|
|
|
|
2015-08-03 21:44:27 +03:00
|
|
|
def autowrap-enable -docstring "Wrap the lines in which characters are inserted" %{
|
2015-07-29 11:48:07 +03:00
|
|
|
hook -group autowrap window InsertChar [^\n] %{
|
2016-03-13 10:47:17 +03:00
|
|
|
eval autowrap-line
|
2015-07-29 11:48:07 +03:00
|
|
|
}
|
2015-07-24 16:00:29 +03:00
|
|
|
}
|
|
|
|
|
2015-08-03 21:44:27 +03:00
|
|
|
def autowrap-disable -docstring "Disable automatic line wrapping" %{
|
2015-07-24 16:00:29 +03:00
|
|
|
rmhooks window autowrap
|
|
|
|
}
|