Allow the autowrap command to break lines as many times as necessary
This commit is contained in:
parent
d86b98fa7c
commit
6ed7bf8821
|
@ -1,8 +1,7 @@
|
||||||
## Maximum amount of characters per line
|
## Maximum amount of characters per line
|
||||||
decl int autowrap_column 80
|
decl int autowrap_column 80
|
||||||
|
|
||||||
## Automatically wrap the selection
|
def -hidden _autowrap-break-line %{
|
||||||
def autowrap-selection -docstring "Wrap the selection" %{
|
|
||||||
try %{
|
try %{
|
||||||
## <a-:><a-;>: ensure that the cursor is located after the anchor, then reverse the
|
## <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)
|
## selection (make sure the cursor is at the beginning of the selection)
|
||||||
|
@ -10,22 +9,35 @@ def autowrap-selection -docstring "Wrap the selection" %{
|
||||||
## the selection is wrap-able (contains at least an horizontal space, any
|
## the selection is wrap-able (contains at least an horizontal space, any
|
||||||
## non-whitespace character, and at least "autowrap_column" characters)
|
## non-whitespace character, and at least "autowrap_column" characters)
|
||||||
## %opt{autowrap_column}l: place the cursor on the "autowrap_column"th character
|
## %opt{autowrap_column}l: place the cursor on the "autowrap_column"th character
|
||||||
## <a-i>w<a-;>;i<ret><esc>: move the cursor to the beginning of the word (if it overslaps
|
## <a-i>w<a-;>;i<ret><esc>: move the cursor to the beginning of the word (if it overlaps
|
||||||
## the "autowrap_column"th column), or do nothing if the "autowrap_column"th
|
## the "autowrap_column"th column), or do nothing if the "autowrap_column"th
|
||||||
## character is a horizontal space, and insert a newline
|
## character is a horizontal space, and insert a newline
|
||||||
## kxXs\h+$<ret>d : select the line that we just made, as well as the one that was just
|
## <a-x>:_autowrap-break-line: select the second half of the buffer that was just split,
|
||||||
## wrapped, and remove any trailing horizontal space
|
## and call itself recursively until all lines in the selection
|
||||||
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>kxXs\h+$<ret>d "
|
## 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>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
## Add a hook that will wrap the entire line every time a key is pressed
|
## Add a hook that will wrap the entire line every time a key is pressed
|
||||||
def autowrap-enable -docstring "Wrap the lines in which characters are inserted" %{
|
def autowrap-enable -docstring "Wrap the lines in which characters are inserted" %{
|
||||||
hook -group autowrap window InsertChar [^\n] %{
|
hook -group autowrap window InsertChar [^\n] %{
|
||||||
try %{
|
|
||||||
exec -draft "<a-x>:autowrap-selection<ret>"
|
exec -draft "<a-x>:autowrap-selection<ret>"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Disable the automatic line wrapping, autowrap-selection remains available though
|
## Disable the automatic line wrapping, autowrap-selection remains available though
|
||||||
|
|
Loading…
Reference in New Issue
Block a user