2015-07-29 10:48:07 +02:00
|
|
|
## Maximum amount of characters per line
|
2015-07-24 15:00:29 +02:00
|
|
|
decl int autowrap_column 80
|
|
|
|
|
2015-09-16 10:58:47 +02:00
|
|
|
def -hidden _autowrap-break-line %{
|
2015-07-29 10:48:07 +02:00
|
|
|
try %{
|
|
|
|
## <a-:><a-;>: ensure that the cursor is located after the anchor, then reverse the
|
|
|
|
## selection (make sure the cursor is at the beginning of the selection)
|
|
|
|
## <a-k>(?=[^\n]*\h)(?=[^\n]*[^\h])[^\n]{%opt{autowrap_column},}[^\n]<ret>: make sure
|
|
|
|
## the selection is wrap-able (contains at least an horizontal space, any
|
|
|
|
## non-whitespace character, and at least "autowrap_column" characters)
|
|
|
|
## %opt{autowrap_column}l: place the cursor on the "autowrap_column"th character
|
2015-09-16 10:58:47 +02:00
|
|
|
## <a-i>w<a-;>;i<ret><esc>: move the cursor to the beginning of the word (if it overlaps
|
2015-07-29 10:48:07 +02:00
|
|
|
## the "autowrap_column"th column), or do nothing if the "autowrap_column"th
|
|
|
|
## character is a horizontal space, and insert a newline
|
2015-09-16 10:58:47 +02:00
|
|
|
## <a-x>:_autowrap-break-line: select the second half of the buffer that was just split,
|
|
|
|
## and call itself recursively until all lines in the selection
|
|
|
|
## are correctly split
|
|
|
|
exec -draft "<a-:><a-;>
|
|
|
|
<a-k>(?=[^\n]*\h)(?=[^\n]*[^\h])[^\n]{%opt{autowrap_column},}[^\n]<ret>
|
|
|
|
%opt{autowrap_column}l
|
|
|
|
<a-i>w<a-;>;i<ret><esc>
|
|
|
|
<a-x>:_autowrap-break-line<ret>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## Automatically wrap the selection
|
|
|
|
def autowrap-selection -docstring "Wrap the selection" %{
|
|
|
|
eval -draft _autowrap-break-line
|
|
|
|
|
|
|
|
try %{
|
|
|
|
exec -draft "<a-k>^[^\n]*\h*\n\h*[^\n]+$<ret>
|
|
|
|
s\h*\n\h*(?=[^\z])<ret>c<ret><esc>"
|
2015-07-29 10:48:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
## Add a hook that will wrap the entire line every time a key is pressed
|
2015-08-03 20:44:27 +02:00
|
|
|
def autowrap-enable -docstring "Wrap the lines in which characters are inserted" %{
|
2015-07-29 10:48:07 +02:00
|
|
|
hook -group autowrap window InsertChar [^\n] %{
|
2015-09-16 10:58:47 +02:00
|
|
|
exec -draft "<a-x>:autowrap-selection<ret>"
|
2015-07-29 10:48:07 +02:00
|
|
|
}
|
2015-07-24 15:00:29 +02:00
|
|
|
}
|
|
|
|
|
2015-07-29 10:48:07 +02:00
|
|
|
## Disable the automatic line wrapping, autowrap-selection remains available though
|
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
|
|
|
|
}
|