Make x just select the full lines

`x` is often criticized as hard to predict due to its slightly complex
behaviour of selecting next line if the current one is fully selected.

Change `x` to use the previous `<a-x>` behaviour, and change `<a-x>` to
trim to fully selected lines as `<a-X>` did.

Adapt existing indentation script to the new behaviour
This commit is contained in:
Maxime Coste 2022-03-17 09:20:07 +11:00
parent 046be3b06c
commit ef8a11b3db
82 changed files with 411 additions and 430 deletions

View File

@ -9,6 +9,9 @@ released versions.
* `!` and `<a-!>` commands now select the inserted text
* `x` now just extends the selection to contain full lines (as `<a-x>` did)
`<a-x>` trims partial lines from the selection (as `<a-X>` did)
== Kakoune 2021.11.07
* Support for curly and separately colored underlines (undocumented in 2021.10.28)

View File

@ -162,13 +162,9 @@ the Shift modifier and moving will extend each selection instead.
characters, see the `matching_pairs` option in <<options#,`:doc options`>>
*x*::
select line on which the end of each selection lies (or next line when end lies
on an end-of-line)
*<a-x>*::
expand selections to contain full lines (including end-of-lines)
*<a-X>*::
*<a-x>*::
trim selections to only contain full lines (not including last
end-of-line)

View File

@ -117,7 +117,7 @@ define-command -hidden modeline-parse-impl %{
define-command modeline-parse -docstring "Read and interpret vi-format modelines at the beginning/end of the buffer" %{
try %{ evaluate-commands -draft %{
execute-keys <percent> "s(?S)\A(.+\n){,%opt{modelines}}|(.+\n){,%opt{modelines}}\z<ret>" \
s^\S*?\s+?\w+:\s?[^\n]+<ret> <a-x>
s^\S*?\s+?\w+:\s?[^\n]+<ret> x
evaluate-commands -draft -itersel modeline-parse-impl
} }
}

View File

@ -73,16 +73,16 @@ define-command -hidden awk-indent-on-new-line %[
# preserve previous line indent
try %[ execute-keys -draft <semicolon> K <a-&> ]
# cleanup trailing whitespaces from previous line
try %[ execute-keys -draft k <a-x> s \h+$ <ret> d ]
try %[ execute-keys -draft k x s \h+$ <ret> d ]
# indent after line ending in opening curly brace
try %[ execute-keys -draft k<a-x> <a-k>\{\h*(#.*)?$<ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k>\{\h*(#.*)?$<ret> j<a-gt> ]
# deindent closing brace when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
]
]
define-command -hidden awk-trim-indent %{
try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d }
try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d }
}
@

View File

@ -64,7 +64,7 @@ provide-module c-family %§
define-command -hidden c-family-trim-indent %{
# remove the line if it's empty when leaving the insert mode
try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> d }
try %{ execute-keys -draft x 1s^(\h+)$<ret> d }
}
define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -itersel %<
@ -75,31 +75,31 @@ define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -i
> catch %<
# else if previous line closed a paren (possibly followed by words and a comment),
# copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
execute-keys -draft kx 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
> catch %<
# else indent new lines with the same level as the previous one
execute-keys -draft K <a-&>
>
# remove previous empty lines resulting from the automatic indent
try %< execute-keys -draft k <a-x> <a-k>^\h+$<ret> Hd >
try %< execute-keys -draft k x <a-k>^\h+$<ret> Hd >
# indent after an opening brace or parenthesis at end of line
try %< execute-keys -draft k <a-x> <a-k>[{(]\h*$<ret> j <a-gt> >
try %< execute-keys -draft k x <a-k>[{(]\h*$<ret> j <a-gt> >
# indent after a label
try %< execute-keys -draft k <a-x> s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
try %< execute-keys -draft k x s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
# indent after a statement not followed by an opening brace
try %< execute-keys -draft k <a-x> s\)\h*(?://[^\n]+)?\n\z<ret> \
try %< execute-keys -draft k x s\)\h*(?://[^\n]+)?\n\z<ret> \
<a-semicolon>mB <a-k>\A\b(if|for|while)\b<ret> <a-semicolon>j <a-gt> >
try %< execute-keys -draft k <a-x> s \belse\b\h*(?://[^\n]+)?\n\z<ret> \
try %< execute-keys -draft k x s \belse\b\h*(?://[^\n]+)?\n\z<ret> \
j <a-gt> >
# deindent after a single line statement end
try %< execute-keys -draft K <a-x> <a-k>\;\h*(//[^\n]+)?$<ret> \
K <a-x> s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z<ret> \
try %< execute-keys -draft K x <a-k>\;\h*(//[^\n]+)?$<ret> \
K x s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z<ret> \
MB <a-k>\A\b(if|for|while)\b<ret> <a-S>1<a-&> >
try %< execute-keys -draft K <a-x> <a-k>\;\h*(//[^\n]+)?$<ret> \
K <a-x> s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z<ret> \
try %< execute-keys -draft K x <a-k>\;\h*(//[^\n]+)?$<ret> \
K x s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z<ret> \
<a-S>1<a-&> >
# deindent closing brace(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <esc> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <esc> m <a-S> 1<a-&> >
# align to the opening parenthesis or opening brace (whichever is first)
# on a previous line if its followed by text on the same line
try %< evaluate-commands -draft %<
@ -118,7 +118,7 @@ define-command -hidden c-family-indent-on-opening-curly-brace %[
# align indent with opening paren when { is entered on a new line after the closing paren
try %[ execute-keys -draft -itersel h<a-F>)M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> <a-S> 1<a-&> ]
# align indent with opening paren when { is entered on a new line after the else
try %[ execute-keys -draft -itersel hK <a-x> s \belse\b\h*(?://[^\n]+)?\n\h*\{<ret> <a-S> 1<a-&> ]
try %[ execute-keys -draft -itersel hK x s \belse\b\h*(?://[^\n]+)?\n\h*\{<ret> <a-S> 1<a-&> ]
]
define-command -hidden c-family-indent-on-closing-curly-brace %[
@ -134,7 +134,7 @@ define-command -hidden c-family-indent-on-closing-curly-brace %[
define-command -hidden c-family-insert-on-closing-curly-brace %[
# add a semicolon after a closing brace if part of a class, union or struct definition
try %[ execute-keys -itersel -draft hm<a-x>B<a-x> <a-K>\A[^\n]+\)\h*(\{|$)<ret> <a-k>\A\h*(class|struct|union|enum)<ret> '<a-;>;i;<esc>' ]
try %[ execute-keys -itersel -draft hmxBx <a-K>\A[^\n]+\)\h*(\{|$)<ret> <a-k>\A\h*(class|struct|union|enum)<ret> '<a-;>;i;<esc>' ]
]
define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[
@ -142,10 +142,10 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel
try %[
evaluate-commands -draft -save-regs '/"' %[
# copy the commenting prefix
execute-keys -save-regs '' k <a-x>1s^\h*(//+\h*)<ret> y
execute-keys -save-regs '' k x1s^\h*(//+\h*)<ret> y
try %[
# if the previous comment isn't empty, create a new one
execute-keys <a-x><a-K>^\h*//+\h*$<ret> j<a-x>s^\h*<ret>P
execute-keys x<a-K>^\h*//+\h*$<ret> jxs^\h*<ret>P
] catch %[
# if there is no text in the previous comment, remove it completely
execute-keys d
@ -153,28 +153,28 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel
]
# trim trailing whitespace on the previous line
try %[ execute-keys -draft k <a-x> s\h+$<ret> d ]
try %[ execute-keys -draft k x s\h+$<ret> d ]
]
try %[
# if the previous line isn't within a comment scope, break
execute-keys -draft k<a-x> <a-k>^(\h*/\*|\h+\*(?!/))<ret>
execute-keys -draft kx <a-k>^(\h*/\*|\h+\*(?!/))<ret>
# find comment opening, validate it was not closed, and check its using star prefixes
execute-keys -draft <a-?>/\*<ret><a-H> <a-K>\*/<ret> <a-k>\A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z<ret>
try %[
# if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft kx<a-k>^\h*/\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the next line is a comment line insert a star
execute-keys -draft j<a-x><a-k>^\h+\*<ret>
execute-keys -draft jx<a-k>^\h+\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the previous line is an empty comment line, close the comment scope
execute-keys -draft k<a-x><a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
execute-keys -draft kx<a-k>^\h+\*\h+$<ret> x1s\*(\h*)<ret>c/<esc>
] catch %[
# if the previous line is a non-empty comment line, add a star
execute-keys -draft i*<space><esc>
@ -183,9 +183,9 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel
]
# trim trailing whitespace on the previous line
try %[ execute-keys -draft k <a-x> s\h+$<ret> d ]
try %[ execute-keys -draft k x s\h+$<ret> d ]
# align the new star with the previous one
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
execute-keys Kx1s^[^*]*(\*)<ret>&
]
] ]

View File

@ -48,13 +48,13 @@ add-highlighter shared/cabal/code/ regex ^\h*([A-Za-z][A-Za-z0-9_-]*)\h*: 1:vari
define-command -hidden cabal-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden cabal-insert-on-new-line %[
evaluate-commands -draft -itersel %[
# copy '--' comment prefix and following white spaces
try %[ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P ]
try %[ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P ]
]
]
@ -65,9 +65,9 @@ define-command -hidden cabal-indent-on-new-line %[
# filter previous line
try %[ execute-keys -draft k : cabal-trim-indent <ret> ]
# indent after lines ending with { or :
try %[ execute-keys -draft <space> k <a-x> <a-k> [:{]$ <ret> j <a-gt> ]
try %[ execute-keys -draft <space> k x <a-k> [:{]$ <ret> j <a-gt> ]
# deindent closing brace when after cursor
try %[ execute-keys -draft <a-x> <a-k> \h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> \h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
]
]

View File

@ -65,7 +65,7 @@ add-highlighter shared/coffee/code/ regex \b(break|case|catch|class|const|contin
define-command -hidden coffee-trim-indent %{
evaluate-commands -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -74,7 +74,7 @@ define-command -hidden coffee-trim-indent %{
define-command -hidden coffee-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s '^\h*\K#\h*' <ret> y gh j P }
try %{ execute-keys -draft k x s '^\h*\K#\h*' <ret> y gh j P }
}
}
@ -85,7 +85,7 @@ define-command -hidden coffee-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : coffee-trim-indent <ret> }
# indent after start structure
try %{ execute-keys -draft k <a-x> <a-k> ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ <ret> j <a-gt> }
}
}

View File

@ -112,13 +112,13 @@ evaluate-commands %sh{
# Hence here only a simple mechanism of copying indent is done.
define-command -hidden coq-copy-indent-on-newline %{
evaluate-commands -draft -itersel %{
try %{ execute-keys -draft k <a-x> s ^\h+ <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h+ <ret> y gh j P }
}
}
define-command -hidden coq-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}

View File

@ -181,7 +181,7 @@ evaluate-commands %sh[
define-command -hidden crystal-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h+$ <ret> d }
}
@ -190,15 +190,15 @@ define-command -hidden crystal-trim-indent %{
define-command -hidden crystal-indent-on-char %{
evaluate-commands -no-hooks -draft -itersel %{
# align 'else' to 'if/case'
try %{ execute-keys -draft <a-x> <a-k> ^\h*else$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:if|case) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^\h*else$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:if|case) <ret> <a-S> 1<a-&> }
# align 'elsif' to 'if'
try %{ execute-keys -draft <a-x> <a-k> ^\h*elsif$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:if) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^\h*elsif$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:if) <ret> <a-S> 1<a-&> }
# align 'when' to 'case'
try %{ execute-keys -draft <a-x> <a-k> ^\h*when$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:case) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^\h*when$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:case) <ret> <a-S> 1<a-&> }
# align 'rescue' to 'begin/def'
try %{ execute-keys -draft <a-x> <a-k> ^\h*rescue$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:begin|def) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^\h*rescue$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:begin|def) <ret> <a-S> 1<a-&> }
# align 'end' to opening structure
try %{ execute-keys -draft <a-x> <a-k> ^\h*end$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^\h*end$ <ret> <a-a>i <a-semicolon> <a-?> ^\h*(?:begin|case|class|def|for|if|module|unless|until|while) <ret> <a-S> 1<a-&> }
}
}
@ -209,23 +209,23 @@ define-command -hidden crystal-indent-on-new-line %{
# Remove previous line's trailing spaces
try %{ execute-keys -draft k :crystal-trim-indent <ret> }
# Indent after start structure/opening statement
try %{ execute-keys -draft k <a-x> <a-k> ^\h*(?:begin|case|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> ^\h*(?:begin|case|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] <ret> j <a-gt> }
}
}
define-command -hidden crystal-insert-on-new-line %[
evaluate-commands -no-hooks -draft -itersel %[
# copy _#_ comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s '^\h*\K#\h*' <ret> y j <a-x><semicolon> P }
try %{ execute-keys -draft k x s '^\h*\K#\h*' <ret> y j x<semicolon> P }
# wisely add end structure
evaluate-commands -save-regs x %[
try %{ execute-keys -draft k <a-x> s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %{ execute-keys -draft k x s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %[
evaluate-commands -draft %[
# Check if previous line opens a block
execute-keys -draft k<a-x> <a-k>^<c-r>x(?:begin|case|class|def|for|if|module|unless|until|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?]<ret>
execute-keys -draft kx <a-k>^<c-r>x(?:begin|case|class|def|for|if|module|unless|until|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?]<ret>
# Check that we do not already have an end for this indent level which is first set via `crystal-indent-on-new-line` hook
execute-keys -draft }i J <a-x> <a-K> ^<c-r>x(?:end|else|elsif|rescue|when)[^0-9A-Za-z_!?]<ret>
execute-keys -draft }i J x <a-K> ^<c-r>x(?:end|else|elsif|rescue|when)[^0-9A-Za-z_!?]<ret>
]
execute-keys -draft o<c-r>xend<esc> # insert a new line with containing end
]

View File

@ -112,7 +112,7 @@ add-highlighter shared/css/attr_selector/single_string region "'" (?<!\\)(\\\\)
define-command -hidden css-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden css-indent-on-new-line %[
@ -124,17 +124,17 @@ define-command -hidden css-indent-on-new-line %[
> catch %<
# else if previous line closed a paren (possibly followed by words and a comment),
# copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
execute-keys -draft kx 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
> catch %<
# else indent new lines with the same level as the previous one
execute-keys -draft K <a-&>
>
# filter previous line
try %< execute-keys -draft k <a-x> <a-k>^\h+$<ret> Hd >
try %< execute-keys -draft k x <a-k>^\h+$<ret> Hd >
# indent after lines ending with with {
try %[ execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> ]
try %[ execute-keys -draft k x <a-k> \{$ <ret> j <a-gt> ]
# deindent closing brace when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
]
]
@ -143,24 +143,24 @@ define-command -hidden css-insert-on-new-line %[
execute-keys <semicolon>
try %[
# if the previous line isn't within a comment scope, break
execute-keys -draft k<a-x> <a-k>^(\h*/\*|\h+\*(?!/))<ret>
execute-keys -draft kx <a-k>^(\h*/\*|\h+\*(?!/))<ret>
# find comment opening, validate it was not closed, and check its using star prefixes
execute-keys -draft <a-?>/\*<ret><a-H> <a-K>\*/<ret> <a-k>\A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z<ret>
try %[
# if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft kx<a-k>^\h*/\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the next line is a comment line insert a star
execute-keys -draft j<a-x><a-k>^\h+\*<ret>
execute-keys -draft jx<a-k>^\h+\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the previous line is an empty comment line, close the comment scope
execute-keys -draft k<a-x><a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
execute-keys -draft kx<a-k>^\h+\*\h+$<ret> x1s\*(\h*)<ret>c/<esc>
] catch %[
# if the previous line is a non-empty comment line, add a star
execute-keys -draft i*<space><esc>
@ -171,7 +171,7 @@ define-command -hidden css-insert-on-new-line %[
# trim trailing whitespace on the previous line
try %[ execute-keys -draft s\h+$<ret> d ]
# align the new star with the previous one
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
execute-keys Kx1s^[^*]*(\*)<ret>&
]
>
]

View File

@ -78,13 +78,13 @@ add-highlighter shared/cucumber/code/ regex \b(Feature|Business\h+Need|Ability|B
define-command -hidden cucumber-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden cucumber-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
}
}

View File

@ -122,13 +122,13 @@ evaluate-commands %sh{
define-command -hidden cue-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden cue-insert-on-new-line %~
evaluate-commands -draft -itersel %<
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K//[!/]?\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K//[!/]?\h* <ret> y<c-o>P<esc> }
>
~
@ -138,13 +138,13 @@ define-command -hidden cue-indent-on-new-line %~
try %{ execute-keys -draft <semicolon> K <a-&> }
try %<
# only if we didn't copy a comment
execute-keys -draft <a-x> <a-K> ^\h*// <ret>
execute-keys -draft x <a-K> ^\h*// <ret>
# indent after lines ending with { or (
try %[ execute-keys -draft k <a-x> <a-k> [{(]\h*$ <ret> j <a-gt> ]
try %[ execute-keys -draft k x <a-k> [{(]\h*$ <ret> j <a-gt> ]
# indent after lines ending with [{(].+ and move first parameter to own line
try %< execute-keys -draft [c[({],[)}] <ret> <a-k> \A[({][^\n]+\n[^\n]*\n?\z <ret> L i<ret><esc> <gt> <a-S> <a-&> >
# deindent closing brace(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> >
>
# filter previous line
try %{ execute-keys -draft k : cue-trim-indent <ret> }

View File

@ -17,7 +17,7 @@ hook global WinSetOption filetype=d %{
set-option window static_words %opt{d_static_words}
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group d-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group d-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group d-insert d-insert-on-new-line
hook window InsertChar \n -group d-indent d-indent-on-new-line
hook window InsertChar \{ -group d-indent d-indent-on-opening-curly-brace
@ -109,7 +109,7 @@ add-highlighter shared/d/code/ regex "\bmodule\s+([\w_-]+)\b" 1:module
define-command -hidden d-insert-on-new-line %~
evaluate-commands -draft -itersel %=
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
=
~
@ -118,17 +118,17 @@ define-command -hidden d-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after if|else|while|for
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-space><a-gt> ]
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
=
~

View File

@ -17,7 +17,7 @@ hook global WinSetOption filetype=dart %{
set-option window static_words %opt{dart_static_words}
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group dart-insert dart-insert-on-new-line
hook window InsertChar \n -group dart-indent dart-indent-on-new-line
hook window InsertChar \{ -group dart-indent dart-indent-on-opening-curly-brace
@ -90,7 +90,7 @@ evaluate-commands %sh{
define-command -hidden dart-insert-on-new-line %~
evaluate-commands -draft -itersel %=
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
=
~
@ -99,17 +99,17 @@ define-command -hidden dart-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after if|else|while|for
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-space><a-gt> ]
# deindent closing brace when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
=
~

View File

@ -78,13 +78,13 @@ add-highlighter shared/dhall/union/end regex > 0:operator
define-command -hidden dhall-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden dhall-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden dhall-indent-on-new-line %{

View File

@ -34,7 +34,7 @@ define-command diff-jump -params .. -docstring %{
set-register c %val{cursor_column}
# If there is a "diff" line, we don't need to look further back.
try %{
execute-keys %{<a-l><semicolon><a-?>^(?:> )*diff\b<ret><a-x>}
execute-keys %{<a-l><semicolon><a-?>^(?:> )*diff\b<ret>x}
} catch %{
# A single file diff won't have a diff line. Start parsing from
# the buffer start, so we can tell if +++/--- lines are headers

View File

@ -89,22 +89,22 @@ add-highlighter shared/elixir/code/ regex '\b\d+[\d_]*\b' 0:value
define-command -hidden elixir-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden elixir-insert-on-new-line %[
evaluate-commands -no-hooks -draft -itersel %[
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y jgi P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y jgi P }
# wisely add end structure
evaluate-commands -save-regs x %[
try %{ execute-keys -draft k <a-x> s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %{ execute-keys -draft k x s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %[
evaluate-commands -draft %[
# Check if previous line opens a block
execute-keys -draft k<a-x> <a-k>^<c-r>x(.+\bdo$)<ret>
execute-keys -draft kx <a-k>^<c-r>x(.+\bdo$)<ret>
# Check that we do not already have an end for this indent level which is first set via `elixir-indent-on-new-line` hook
execute-keys -draft }i J <a-x> <a-K> ^<c-r>x(end|else)[^0-9A-Za-z_!?]<ret>
execute-keys -draft }i J x <a-K> ^<c-r>x(end|else)[^0-9A-Za-z_!?]<ret>
]
execute-keys -draft o<c-r>xend<esc> # insert a new line with containing end
]

View File

@ -55,7 +55,7 @@ add-highlighter shared/elm/code/ regex (?<![-+<>!@#$%^&*=:/\\|])(->|:|=|\|)(?![-
define-command -hidden elm-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden elm-indent-after "
@ -65,7 +65,7 @@ define-command -hidden elm-indent-after "
define-command -hidden elm-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
}
}

View File

@ -39,7 +39,7 @@ add-highlighter shared/elvish/code/metachar regex [*?|&\;<>()[\]{}] 0:operator
define-command -hidden elvish-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -49,19 +49,19 @@ define-command -hidden elvish-indent %< evaluate-commands -draft -itersel %<
execute-keys <semicolon>
try %<
# if the previous line is a comment, copy indent, # and whitespace
execute-keys -draft k <a-x> s^\h*#\h*<ret> yjP
execute-keys -draft k x s^\h*#\h*<ret> yjP
> catch %<
# copy indent
execute-keys -draft K <a-&>
# indent after { [ ( |
try %< execute-keys -draft k <a-x> <a-k>[[{(|]\h*$<ret> j <a-gt> >
try %< execute-keys -draft k x <a-k>[[{(|]\h*$<ret> j <a-gt> >
>
>>
define-command -hidden elvish-deindent %< evaluate-commands -draft -itersel %<
try %<
# Deindent only when there is a lone closing character
execute-keys -draft <a-x> <a-k>^\h*[^\h]$<ret> <a-lt>
execute-keys -draft x <a-k>^\h*[^\h]$<ret> <a-lt>
>
>>
§

View File

@ -45,14 +45,14 @@ add-highlighter shared/fidl/code/literals/binary regex \b(0b[01])\b 0:value
define-command -hidden fidl-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden fidl-indent-on-new-line %~
evaluate-commands -draft -itersel %@
try %{ # line comment
# copy the commenting prefix
execute-keys -draft k <a-x> s ^\h*/{2,}\h* <ret> yjghP
execute-keys -draft k x s ^\h*/{2,}\h* <ret> yjghP
} catch %`
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
@ -61,7 +61,7 @@ define-command -hidden fidl-indent-on-new-line %~
execute-keys -draft <a-k> [)}] <ret> m <a-S> 1<a-&>
+ catch %+
# indent after lines ending with ( or {
try %! execute-keys -draft k <a-x> <a-k> [({]$ <ret> j <a-gt> !
try %! execute-keys -draft k x <a-k> [({]$ <ret> j <a-gt> !
+
`
# remove trailing white spaces

View File

@ -53,23 +53,23 @@ add-highlighter shared/fish/code/ regex \b(?<![$-])(and|argparse|begin|bg|bind|b
define-command -hidden fish-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
# remove trailing white spaces
try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> d }
try %{ execute-keys -draft x 1s^(\h+)$<ret> d }
}
}
define-command -hidden fish-indent-on-char %{
evaluate-commands -no-hooks -draft -itersel %{
# align middle and end structures to start and indent when necessary
try %{ execute-keys -draft <a-x><a-k>^\h*(else)$<ret><a-semicolon><a-?>^\h*(if)<ret>s\A|.\z<ret>1<a-&> }
try %{ execute-keys -draft <a-x><a-k>^\h*(end)$<ret><a-semicolon><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|.\z<ret>1<a-&> }
try %{ execute-keys -draft <a-x><a-k>^\h*(case)$<ret><a-semicolon><a-?>^\h*(switch)<ret>s\A|.\z<ret>1<a-&> }
try %{ execute-keys -draft x<a-k>^\h*(else)$<ret><a-semicolon><a-?>^\h*(if)<ret>s\A|.\z<ret>1<a-&> }
try %{ execute-keys -draft x<a-k>^\h*(end)$<ret><a-semicolon><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|.\z<ret>1<a-&> }
try %{ execute-keys -draft x<a-k>^\h*(case)$<ret><a-semicolon><a-?>^\h*(switch)<ret>s\A|.\z<ret>1<a-&> }
}
}
define-command -hidden fish-insert-on-new-line %{
evaluate-commands -no-hooks -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P }
}
}
@ -78,9 +78,9 @@ define-command -hidden fish-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after start structure
try %{ execute-keys -draft k<a-x><a-k>^\h*(begin|case|else|for|function|if|while)\b<ret>j<a-gt> }
try %{ execute-keys -draft kx<a-k>^\h*(begin|case|else|for|function|if|while)\b<ret>j<a-gt> }
}
}

View File

@ -128,7 +128,7 @@ add-highlighter shared/fsharp/code/ regex "\B(\(\))\B" 0:value
define-command -hidden fsharp-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -137,7 +137,7 @@ define-command -hidden fsharp-trim-indent %{
define-command -hidden fsharp-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy // comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*//\h* <ret> y jgh P }
try %{ execute-keys -draft k x s ^\h*//\h* <ret> y jgh P }
}
}
@ -146,11 +146,11 @@ define-command -hidden fsharp-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft \; K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after line ending with =
try %{ execute-keys -draft <space> k <a-x> <a-k> =$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> =$ <ret> j <a-gt> }
# indent after line ending with "do"
try %{ execute-keys -draft <space> k <a-x> <a-k> \bdo$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> \bdo$ <ret> j <a-gt> }
}
}

View File

@ -79,7 +79,7 @@ add-highlighter shared/gas/code/ regex \
define-command -hidden gas-trim-indent %{
evaluate-commands -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h+$ <ret> d }
}
@ -92,7 +92,7 @@ define-command -hidden gas-indent-on-new-line %~
# filter previous line
try %{ execute-keys -draft k : gas-trim-indent <ret> }
# indent after label
try %[ execute-keys -draft k <a-x> <a-k> :$ <ret> j <a-gt> ]
try %[ execute-keys -draft k x <a-k> :$ <ret> j <a-gt> ]
>
~

View File

@ -19,7 +19,7 @@ hook global WinSetOption filetype=gdscript %{
hook window InsertChar \n -group gdscript-insert gdscript-insert-on-new-line
hook window InsertChar \n -group gdscript-indent gdscript-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group gdscript-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group gdscript-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gdscript-.+ }
}
@ -90,7 +90,7 @@ add-highlighter shared/gdscript/code/ regex '\$[\w/]*' 0:
define-command -hidden gdscript-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P }
}
}
@ -99,11 +99,11 @@ define-command -hidden gdscript-indent-on-new-line %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after line ending with :
try %{ execute-keys -draft <space> k <a-x> <a-k> :$ <ret> <a-K> ^\h*# <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> :$ <ret> <a-K> ^\h*# <ret> j <a-gt> }
# deindent closing brace/bracket when after cursor (for arrays and dictionaries)
try %< execute-keys -draft <a-x> <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>

View File

@ -76,13 +76,13 @@ add-highlighter shared/gluon/code/ regex \B'([^\\]|[\\]['"\w\d\\])' 0:string
define-command -hidden gluon-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden gluon-insert-on-new-line %~
evaluate-commands -draft -itersel %_
# copy // and /// comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K///?\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K///?\h* <ret> y gh j P }
_
~
@ -96,7 +96,7 @@ define-command -hidden gluon-indent-on-new-line %~
# or in
try %{ execute-keys -draft \; k x <a-k> (\(|\{|\[|=|->|\b(?:then|else|rec|in))$ <ret> j <a-gt> }
# deindent closing brace(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})\]] <ret> gh / \})\]] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[})\]] <ret> gh / \})\]] <ret> m <a-S> 1<a-&> >
_
~

View File

@ -17,7 +17,7 @@ hook global WinSetOption filetype=go %{
set-option window static_words %opt{go_static_words}
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group go-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group go-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group go-indent go-indent-on-new-line
hook window InsertChar \{ -group go-indent go-indent-on-opening-curly-brace
hook window InsertChar \} -group go-indent go-indent-on-closing-curly-brace
@ -103,10 +103,10 @@ define-command -hidden go-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
try %{
try %{ # line comment
execute-keys -draft k<a-x> s ^\h*// <ret>
execute-keys -draft kx s ^\h*// <ret>
} catch %{ # block comment
execute-keys -draft <a-?> /\* <ret> <a-K>\*/<ret>
}
@ -114,9 +114,9 @@ define-command -hidden go-indent-on-new-line %~
# indent after lines with an unclosed { or (
try %< execute-keys -draft [c[({],[)}] <ret> <a-k> \A[({][^\n]*\n[^\n]*\n?\z <ret> j<a-gt> >
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
}
=
~
@ -134,7 +134,7 @@ define-command -hidden go-indent-on-closing-curly-brace %[
define-command -hidden go-insert-comment-on-new-line %[
evaluate-commands -no-hooks -draft -itersel %[
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
]
]
@ -143,28 +143,28 @@ define-command -hidden go-insert-closing-delimiter-on-new-line %[
# Wisely add '}'.
evaluate-commands -save-regs x %[
# Save previous line indent in register x.
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft kxs^\h+<ret>"xy ] catch %[ reg x '' ]
try %[
# Validate previous line and that it is not closed yet.
execute-keys -draft k<a-x> <a-k>^<c-r>x.*\{\h*\(?\h*$<ret> j}iJ<a-x> <a-K>^<c-r>x\)?\h*\}<ret>
execute-keys -draft kx <a-k>^<c-r>x.*\{\h*\(?\h*$<ret> j}iJx <a-K>^<c-r>x\)?\h*\}<ret>
# Insert closing '}'.
execute-keys -draft o<c-r>x}<esc>
# Delete trailing '}' on the line below the '{'.
execute-keys -draft Xs\}$<ret>d
execute-keys -draft xs\}$<ret>d
]
]
# Wisely add ')'.
evaluate-commands -save-regs x %[
# Save previous line indent in register x.
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft kxs^\h+<ret>"xy ] catch %[ reg x '' ]
try %[
# Validate previous line and that it is not closed yet.
execute-keys -draft k<a-x> <a-k>^<c-r>x.*\(\h*$<ret> J}iJ<a-x> <a-K>^<c-r>x\)<ret>
execute-keys -draft kx <a-k>^<c-r>x.*\(\h*$<ret> J}iJx <a-K>^<c-r>x\)<ret>
# Insert closing ')'.
execute-keys -draft o<c-r>x)<esc>
# Delete trailing ')' on the line below the '('.
execute-keys -draft Xs\)\h*\}?\h*$<ret>d
execute-keys -draft xs\)\h*\}?\h*$<ret>d
]
]
]

View File

@ -74,7 +74,7 @@ add-highlighter shared/graphql/object/field/expand-fragment regex '\.\.\.(?=\w)'
define-command -hidden graphql-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden graphql-indent-on-char %<
@ -91,9 +91,9 @@ define-command -hidden graphql-indent-on-new-line %<
# filter previous line
try %{ execute-keys -draft k : graphql-trim-indent <ret> }
# indent after lines ending with opener token
try %< execute-keys -draft k <a-x> <a-k> [[{]\h*$ <ret> j <a-gt> >
try %< execute-keys -draft k x <a-k> [[{]\h*$ <ret> j <a-gt> >
# deindent closer token(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>

View File

@ -54,13 +54,13 @@ add-highlighter shared/haml/code/ regex ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-
define-command -hidden haml-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden haml-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '/' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K/\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K/\h* <ret> y gh j P }
}
}
@ -71,7 +71,7 @@ define-command -hidden haml-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : haml-trim-indent <ret> }
# indent after lines beginning with : or -
try %{ execute-keys -draft k <a-x> <a-k> ^\h*[:-] <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> ^\h*[:-] <ret> j <a-gt> }
}
}

View File

@ -95,22 +95,22 @@ provide-module hare %§
# preserve indentation on new lines
try %{ execute-keys -draft <semicolon> K <a-&> }
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j i<tab> ]
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j i<tab> ]
# cleanup trailing white spaces on the previous line
execute-keys -draft k :hare-trim-indent <ret>
# indent after match/switch's case statements
try %[ execute-keys -draft k<a-x> <a-k> case\h.*=>\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> case\h.*=>\h*$ <ret> j<a-gt> ]
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
} }
define-command -hidden hare-insert-on-new-line %{ evaluate-commands -draft -itersel %{
try %{ evaluate-commands -draft -save-regs '/"' %{
# copy the comment prefix
execute-keys -save-regs '' k <a-x> s ^\h*\K//\h* <ret> y
execute-keys -save-regs '' k x s ^\h*\K//\h* <ret> y
try %{
# paste the comment prefix
execute-keys <a-x> j <a-x> s ^\h* <ret>P
execute-keys x j x s ^\h* <ret>P
}
} }
try %{
@ -131,6 +131,6 @@ provide-module hare %§
define-command -hidden hare-trim-indent %{ evaluate-commands -draft -itersel %{
# remove trailing whitespace
try %{ execute-keys -draft <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft x s \h+$ <ret> d }
} }
§

View File

@ -101,13 +101,13 @@ add-highlighter shared/haskell/code/ regex \bderiving\b\s+(?:[A-Z]['\w]+|\([',\w
define-command -hidden haskell-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden haskell-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
}
}

View File

@ -66,7 +66,7 @@ add-highlighter shared/hbs-file/html default-region ref html
define-command -hidden hbs-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden hbs-indent-on-char %[
@ -79,7 +79,7 @@ define-command -hidden hbs-indent-on-char %[
define-command -hidden hbs-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '/' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K/\h* <ret> y j p }
try %{ execute-keys -draft k x s ^\h*\K/\h* <ret> y j p }
}
}
@ -90,7 +90,7 @@ define-command -hidden hbs-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : hbs-trim-indent <ret> }
# indent after lines beginning with : or -
try %{ execute-keys -draft k <a-x> <a-k> ^\h*[:-] <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> ^\h*[:-] <ret> j <a-gt> }
}
}

View File

@ -64,7 +64,7 @@ add-highlighter shared/html/tag/base/ regex <(!DOCTYPE(\h+\w+)+) 1:meta
define-command -hidden html-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden html-indent-on-greater-than %[
@ -81,7 +81,7 @@ define-command -hidden html-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : html-trim-indent <ret> }
# indent after lines ending with opening tag except when it starts with a closing tag
try %{ execute-keys -draft k <a-x> <a-k> <lt>(?!area)(?!base)(?!br)(?!col)(?!command)(?!embed)(?!hr)(?!img)(?!input)(?!keygen)(?!link)(?!menuitem)(?!meta)(?!param)(?!source)(?!track)(?!wbr)(?!/)(?!>)[a-zA-Z0-9_-]+[^>]*?>$ <ret>j<a-x><a-K>^\s*<lt>/<ret><a-gt> } }
try %{ execute-keys -draft k x <a-k> <lt>(?!area)(?!base)(?!br)(?!col)(?!command)(?!embed)(?!hr)(?!img)(?!input)(?!keygen)(?!link)(?!menuitem)(?!meta)(?!param)(?!source)(?!track)(?!wbr)(?!/)(?!>)[a-zA-Z0-9_-]+[^>]*?>$ <ret>jx<a-K>^\s*<lt>/<ret><a-gt> } }
}
]

View File

@ -9,7 +9,7 @@ hook global WinSetOption filetype=i3 %[
require-module i3
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group i3-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group i3-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group i3-insert i3-insert-on-new-line
hook window InsertChar \n -group i3-indent i3-indent-on-new-line
hook window InsertChar \} -group i3-indent i3-indent-on-closing-curly-brace
@ -71,7 +71,7 @@ add-highlighter shared/i3/code/ regex "client\.(focused_inactive|focused_tab_tit
define-command -hidden i3-insert-on-new-line %~
evaluate-commands -draft -itersel %=
# copy # comments prefix
try %{ execute-keys -draft k<a-x> s ^\h*#\h* <ret> y jgh P }
try %{ execute-keys -draft kx s ^\h*#\h* <ret> y jgh P }
=
~
@ -80,9 +80,9 @@ define-command -hidden i3-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with {
try %[ execute-keys -draft k<a-x> <a-k> \{\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> \{\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
=
~

View File

@ -11,7 +11,7 @@ hook global WinSetOption filetype=java %{
set-option window static_words %opt{java_static_words}
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group java-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group java-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group java-insert java-insert-on-new-line
hook window InsertChar \n -group java-indent java-indent-on-new-line
hook window InsertChar \{ -group java-indent java-indent-on-opening-curly-brace
@ -42,7 +42,7 @@ add-highlighter shared/java/code/ regex "(?<!\w)@\w+\b" 0:meta
define-command -hidden java-insert-on-new-line %[
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
]
define-command -hidden java-indent-on-new-line %~
@ -50,17 +50,17 @@ define-command -hidden java-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after keywords
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(if|else|while|for|try|catch)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-space><a-gt> ]
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
=
~

View File

@ -43,7 +43,7 @@ provide-module javascript %§
define-command -hidden javascript-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> d }
try %{ execute-keys -draft x 1s^(\h+)$<ret> d }
}
define-command -hidden javascript-indent-on-char %<
@ -59,10 +59,10 @@ define-command -hidden javascript-insert-on-new-line %<
try %[
evaluate-commands -draft -save-regs '/"' %[
# copy the commenting prefix
execute-keys -save-regs '' k <a-x>1s^\h*(//+\h*)<ret> y
execute-keys -save-regs '' k x1s^\h*(//+\h*)<ret> y
try %[
# if the previous comment isn't empty, create a new one
execute-keys <a-x><a-K>^\h*//+\h*$<ret> j<a-x>s^\h*<ret>P
execute-keys x<a-K>^\h*//+\h*$<ret> jxs^\h*<ret>P
] catch %[
# if there is no text in the previous comment, remove it completely
execute-keys d
@ -71,24 +71,24 @@ define-command -hidden javascript-insert-on-new-line %<
]
try %[
# if the previous line isn't within a comment scope, break
execute-keys -draft k<a-x> <a-k>^(\h*/\*|\h+\*(?!/))<ret>
execute-keys -draft kx <a-k>^(\h*/\*|\h+\*(?!/))<ret>
# find comment opening, validate it was not closed, and check its using star prefixes
execute-keys -draft <a-?>/\*<ret><a-H> <a-K>\*/<ret> <a-k>\A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z<ret>
try %[
# if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft kx<a-k>^\h*/\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the next line is a comment line insert a star
execute-keys -draft j<a-x><a-k>^\h+\*<ret>
execute-keys -draft jx<a-k>^\h+\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the previous line is an empty comment line, close the comment scope
execute-keys -draft k<a-x><a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
execute-keys -draft kx<a-k>^\h+\*\h+$<ret> x1s\*(\h*)<ret>c/<esc>
] catch %[
# if the previous line is a non-empty comment line, add a star
execute-keys -draft i*<space><esc>
@ -99,7 +99,7 @@ define-command -hidden javascript-insert-on-new-line %<
# trim trailing whitespace on the previous line
try %[ execute-keys -draft s\h+$<ret> d ]
# align the new star with the previous one
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
execute-keys Kx1s^[^*]*(\*)<ret>&
]
>
>
@ -113,31 +113,31 @@ define-command -hidden javascript-indent-on-new-line %<
> catch %<
# else if previous line closed a paren (possibly followed by words and a comment),
# copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
execute-keys -draft kx 1s(\))(\h+\w+)*\h*(\;\h*)?(?://[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
> catch %<
# else indent new lines with the same level as the previous one
execute-keys -draft K <a-&>
>
# remove previous empty lines resulting from the automatic indent
try %< execute-keys -draft k <a-x> <a-k>^\h+$<ret> Hd >
try %< execute-keys -draft k x <a-k>^\h+$<ret> Hd >
# indent after an opening brace or parenthesis at end of line
try %< execute-keys -draft k <a-x> <a-k>[{(]\h*$<ret> j <a-gt> >
try %< execute-keys -draft k x <a-k>[{(]\h*$<ret> j <a-gt> >
# indent after a label (works for case statements)
try %< execute-keys -draft k <a-x> s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
try %< execute-keys -draft k x s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
# indent after a statement not followed by an opening brace
try %< execute-keys -draft k <a-x> s\)\h*(?://[^\n]+)?\n\z<ret> \
try %< execute-keys -draft k x s\)\h*(?://[^\n]+)?\n\z<ret> \
<a-semicolon>mB <a-k>\A\b(if|for|while)\b<ret> <a-semicolon>j <a-gt> >
try %< execute-keys -draft k <a-x> s \belse\b\h*(?://[^\n]+)?\n\z<ret> \
try %< execute-keys -draft k x s \belse\b\h*(?://[^\n]+)?\n\z<ret> \
j <a-gt> >
# deindent after a single line statement end
try %< execute-keys -draft K <a-x> <a-k>\;\h*(//[^\n]+)?$<ret> \
K <a-x> s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z<ret> \
try %< execute-keys -draft K x <a-k>\;\h*(//[^\n]+)?$<ret> \
K x s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z<ret> \
MB <a-k>\A\b(if|for|while)\b<ret> <a-S>1<a-&> >
try %< execute-keys -draft K <a-x> <a-k>\;\h*(//[^\n]+)?$<ret> \
K <a-x> s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z<ret> \
try %< execute-keys -draft K x <a-k>\;\h*(//[^\n]+)?$<ret> \
K x s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z<ret> \
<a-S>1<a-&> >
# deindent closing brace(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <esc> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <esc> m <a-S> 1<a-&> >
# align to the opening parenthesis or opening brace (whichever is first)
# on a previous line if its followed by text on the same line
try %< evaluate-commands -draft %<

View File

@ -43,7 +43,7 @@ add-highlighter shared/json/code/ regex \b(true|false|null|\d+(?:\.\d+)?(?:[eE][
define-command -hidden json-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden json-indent-on-char %<
@ -60,9 +60,9 @@ define-command -hidden json-indent-on-new-line %<
# filter previous line
try %{ execute-keys -draft k : json-trim-indent <ret> }
# indent after lines ending with opener token
try %< execute-keys -draft k <a-x> <a-k> [[{]\h*$ <ret> j <a-gt> >
try %< execute-keys -draft k x <a-k> [[{]\h*$ <ret> j <a-gt> >
# deindent closer token(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>

View File

@ -26,7 +26,7 @@ provide-module justfile %{
define-command -hidden justfile-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -37,9 +37,9 @@ define-command -hidden just-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# cleanup trailing white spaces on previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>"_d }
try %{ execute-keys -draft kx s \h+$ <ret>"_d }
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*//\h* <ret> y jgh P }
try %{ execute-keys -draft k x s ^\h*//\h* <ret> y jgh P }
}
}

View File

@ -21,7 +21,7 @@ hook global WinSetOption filetype=kak %~
hook window InsertChar [>)}\]] -group kak-indent kak-indent-on-closing-matching
hook window InsertChar (?![[{(<>)}\]])[^\s\w] -group kak-indent kak-indent-on-closing-char
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group kak-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group kak-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
set-option buffer extra_word_chars '_' '-'
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kak-.+ }
@ -96,7 +96,7 @@ add-highlighter shared/kakrc/single_string/escape regex "''" 0:default+b
define-command -hidden kak-insert-on-new-line %~
evaluate-commands -draft -itersel %=
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P }
=
~
@ -105,13 +105,13 @@ define-command -hidden kak-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after line ending with %\w*[^\s\w]
try %{ execute-keys -draft k <a-x> <a-k> \%\w*[^\s\w]$ <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> \%\w*[^\s\w]$ <ret> j <a-gt> }
# deindent closing brace when after cursor
try %_ execute-keys -draft -itersel <a-x> <a-k> ^\h*([>)}\]]) <ret> gh / <c-r>1 <ret> m <a-S> 1<a-&> _
try %_ execute-keys -draft -itersel x <a-k> ^\h*([>)}\]]) <ret> gh / <c-r>1 <ret> m <a-S> 1<a-&> _
# deindent closing char(s)
try %{ execute-keys -draft -itersel <a-x> <a-k> ^\h*([^\s\w]) <ret> gh / <c-r>1 <ret> <a-?> <c-r>1 <ret> <a-T>% <a-k> \w*<c-r>1$ <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft -itersel x <a-k> ^\h*([^\s\w]) <ret> gh / <c-r>1 <ret> <a-?> <c-r>1 <ret> <a-T>% <a-k> \w*<c-r>1$ <ret> <a-S> 1<a-&> }
=
~

View File

@ -20,7 +20,7 @@ hook global WinSetOption filetype=kotlin %{
set-option window static_words %opt{kotlin_static_words}
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group kotlin-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group kotlin-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group kotlin-indent kotlin-insert-on-new-line
hook window InsertChar \n -group kotlin-indent kotlin-indent-on-new-line
hook window InsertChar \{ -group kotlin-indent kotlin-indent-on-opening-curly-brace
@ -108,7 +108,7 @@ add-highlighter shared/kotlin/code/discolour regex ^(package|import)(?S)(.+) 2:d
# ‾‾‾‾‾‾‾‾
define-command -hidden kotlin-insert-on-new-line %[
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
]
define-command -hidden kotlin-indent-on-new-line %~
@ -116,19 +116,19 @@ define-command -hidden kotlin-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# indent after a pattern match on when/where statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(when|where).*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> ^\h*(when|where).*$ <ret> j<a-gt> ]
# indent after term on an expression
try %[ execute-keys -draft k<a-x> <a-k> =\h*?$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> =\h*?$ <ret> j<a-gt> ]
# indent after keywords
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(catch|do|else|for|if|try|while)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-space><a-gt> ]
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
>
~

View File

@ -80,27 +80,27 @@ add-highlighter shared/latex/content/ regex '((?<!\\)(?:\\\\)*\K\$(\\\$|[^$])+\$
define-command -hidden latex-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
try %{ execute-keys <a-x> 1s^(\h+)$<ret> d }
try %{ execute-keys x 1s^(\h+)$<ret> d }
}
}
define-command -hidden latex-indent-newline %(
evaluate-commands -no-hooks -draft -itersel %(
# copy '%' comment prefix and following white spaces
try %{ execute-keys -draft k<a-x> s^\h*%\h*<ret> y jgh P }
try %{ execute-keys -draft kx s^\h*%\h*<ret> y jgh P }
# preserve previous line indent
try %{ execute-keys -draft K<a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k<a-x> s\h+$<ret> d }
try %{ execute-keys -draft kx s\h+$<ret> d }
# indent after line ending with {
try %( execute-keys -draft k<a-x> <a-k>\{$<ret> j<a-gt> )
try %( execute-keys -draft kx <a-k>\{$<ret> j<a-gt> )
# deindent closing brace(s) when after cursor
try %( execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> )
try %( execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> )
# indent after line ending with \begin{...}[...]{...}, with multiple
# sets of arguments possible
try %(
execute-keys -draft \
k<a-x> \
kx \
<a-k>\\begin\h*\{[^\}]+\}(\h|\[.*\]|\{.*\})*$<ret> \
j<a-gt>
)
@ -110,7 +110,7 @@ define-command -hidden latex-indent-newline %(
define-command -hidden latex-indent-closing-brace %(
evaluate-commands -no-hooks -draft -itersel %(
# Align lone } with matching bracket
try %( execute-keys -draft <a-x>_ <a-k>\A\}\z<ret> m<a-S>1<a-&> )
try %( execute-keys -draft x_ <a-k>\A\}\z<ret> m<a-S>1<a-&> )
# Align \end{...} with corresponding \begin{...}
try %(
execute-keys -draft h<a-h> 1s\\end\h*\{([^\}]+)\}\z<ret> \
@ -124,12 +124,12 @@ define-command -hidden latex-insert-on-new-line %(
# Wisely add "\end{...}".
evaluate-commands -save-regs xz %(
# Save previous line indent in register x.
try %( execute-keys -draft k<a-x>s^\h+<ret>"xy ) catch %( reg x '' )
try %( execute-keys -draft kxs^\h+<ret>"xy ) catch %( reg x '' )
# Save item of begin in register z.
try %( execute-keys -draft k<a-x>s\{.*\}<ret>"zy ) catch %( reg z '' )
try %( execute-keys -draft kxs\{.*\}<ret>"zy ) catch %( reg z '' )
try %(
# Validate previous line and that it is not closed yet.
execute-keys -draft k<a-x> <a-k>^<c-r>x\h*\\begin\{.*\}<ret> J}iJ<a-x> <a-K>^<c-r>x(\\end\<c-r>z<backspace>\})<ret>
execute-keys -draft kx <a-k>^<c-r>x\h*\\begin\{.*\}<ret> J}iJx <a-K>^<c-r>x(\\end\<c-r>z<backspace>\})<ret>
# Auto insert "\end{...}".
execute-keys -draft o<c-r>x\end<c-r>z<esc>
)

View File

@ -129,14 +129,14 @@ define-command -hidden ledger-indent-on-new-line %[
# preserve previous line indent
try %[ execute-keys -draft <semicolon> K <a-&> ]
# cleanup trailing whitespaces from previous line
try %[ execute-keys -draft k <a-x> s \h+$ <ret> d ]
try %[ execute-keys -draft k x s \h+$ <ret> d ]
# indent after the first line of a transaction
try %[ execute-keys -draft k<a-x> <a-k>^[0-9]<ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k>^[0-9]<ret> j<a-gt> ]
]
]
define-command -hidden ledger-trim-indent %{
try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d }
try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d }
}
]

View File

@ -48,7 +48,7 @@ add-highlighter shared/lisp/code/ regex (\b\d+)?\.\d+([eEsSfFdDlL]\d+)?\b 0:valu
define-command -hidden lisp-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
declare-option \

View File

@ -87,7 +87,7 @@ define-command lua-alternative-file -docstring 'Jump to the alternate file (impl
define-command -hidden lua-trim-indent %[
# remove trailing whitespaces
try %[ execute-keys -draft -itersel <a-x> s \h+$ <ret> d ]
try %[ execute-keys -draft -itersel x s \h+$ <ret> d ]
]
define-command -hidden lua-indent-on-char %[
@ -112,7 +112,7 @@ define-command -hidden lua-indent-on-new-line %[
# - or contains an unclosed function expression,
# - or ends with an enclosed '(' or '{'
try %[ execute-keys -draft \
<space> K<a-x> \
<space> Kx \
<a-K>\A\h*--<ret> \
<a-K>\A[^\n]*\b(end|until)\b<ret> \
<a-k>\A(\h*\b(do|else|elseif|for|function|if|repeat|while)\b|[^\n]*[({]$|[^\n]*\bfunction\b\h*[(])<ret> \
@ -124,23 +124,23 @@ define-command -hidden lua-indent-on-new-line %[
define-command -hidden lua-insert-on-new-line %[
evaluate-commands -no-hooks -draft -itersel %[
# copy -- comment prefix and following white spaces
try %[ execute-keys -draft k<a-x>s^\h*\K--\h*<ret> y gh j <a-x><semicolon> P ]
try %[ execute-keys -draft kxs^\h*\K--\h*<ret> y gh j x<semicolon> P ]
# wisely add end structure
evaluate-commands -save-regs x %[
# save previous line indent in register x
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft kxs^\h+<ret>"xy ] catch %[ reg x '' ]
try %[
# check that starts with a block keyword that is not closed on the same line
execute-keys -draft \
k<a-x> \
kx \
<a-k>^\h*\b(else|elseif|do|for|function|if|while)\b|[^\n]\bfunction\b\h*[(]<ret> \
<a-K>\bend\b<ret>
# check that the block is empty and is not closed on a different line
execute-keys -draft <a-a>i <a-K>^[^\n]+\n[^\n]+\n<ret> j<a-x> <a-K>^<c-r>x\b(else|elseif|end)\b<ret>
execute-keys -draft <a-a>i <a-K>^[^\n]+\n[^\n]+\n<ret> jx <a-K>^<c-r>x\b(else|elseif|end)\b<ret>
# auto insert end
execute-keys -draft o<c-r>xend<esc>
# auto insert ) for anonymous function
execute-keys -draft k<a-x><a-k>\([^)\n]*function\b<ret>jjA)<esc>
execute-keys -draft kx<a-k>\([^)\n]*function\b<ret>jjA)<esc>
]
]
]

View File

@ -53,7 +53,7 @@ evaluate-commands %sh{
define-command -hidden makefile-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -64,11 +64,11 @@ define-command -hidden makefile-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
## If the line above is a target indent with a tab
try %{ execute-keys -draft Z k<a-x> <a-k>^\S.*?(::|:|!)\s<ret> z i<tab> }
try %{ execute-keys -draft Z kx <a-k>^\S.*?(::|:|!)\s<ret> z i<tab> }
# cleanup trailing white space son previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# indent after some keywords
try %{ execute-keys -draft Z k<a-x> <a-k> ^\h*(ifeq|ifneq|ifdef|ifndef|else|define)\b<ret> z <a-gt> }
try %{ execute-keys -draft Z kx <a-k> ^\h*(ifeq|ifneq|ifdef|ifndef|else|define)\b<ret> z <a-gt> }
}
}

View File

@ -102,14 +102,14 @@ add-highlighter shared/markdown/inline/text/ regex "\H( {2,})$" 1:+r@meta
define-command -hidden markdown-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
}
define-command -hidden markdown-insert-on-new-line %{
try %{ execute-keys -draft -itersel k <a-x> s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* <ret> y gh j P }
try %{ execute-keys -draft -itersel k x s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* <ret> y gh j P }
}
define-command -hidden markdown-indent-on-new-line %{
@ -117,7 +117,7 @@ define-command -hidden markdown-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# remove trailing white spaces
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
}
}

View File

@ -16,7 +16,7 @@ hook global WinSetOption filetype=mercury %{
hook window InsertChar \n -group mercury-insert mercury-insert-on-new-line
hook window InsertChar \n -group mercury-indent mercury-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group mercury-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group mercury-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window mercury-.+ }
}
@ -97,7 +97,7 @@ evaluate-commands %sh{
define-command -hidden mercury-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '%' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\%\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\%\h* <ret> y gh j P }
}
}
@ -113,11 +113,11 @@ define-command -hidden mercury-indent-on-new-line %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after line ending with :-
try %{ execute-keys -draft <space> k <a-x> <a-k> :-$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> :-$ <ret> j <a-gt> }
# deindent closing brace/bracket when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[}\])] <ret> gh / [}\])] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[}\])] <ret> gh / [}\])] <ret> m <a-S> 1<a-&> >
>
>

View File

@ -80,7 +80,7 @@ define-command moon-alternative-file -docstring 'Jump to the alternate file (imp
define-command -hidden moon-trim-indent %{
evaluate-commands -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -89,18 +89,18 @@ define-command -hidden moon-trim-indent %{
define-command -hidden moon-indent-on-char %{
evaluate-commands -draft -itersel %{
# align _else_ statements to start
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (else(if)?) $ <ret> <a-semicolon> <a-?> ^ \h * (if|unless|when) <ret> s \A | \z <ret> ) <a-&> }
try %{ execute-keys -draft x <a-k> ^ \h * (else(if)?) $ <ret> <a-semicolon> <a-?> ^ \h * (if|unless|when) <ret> s \A | \z <ret> ) <a-&> }
# align _when_ to _switch_ then indent
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (when) $ <ret> <a-semicolon> <a-?> ^ \h * (switch) <ret> s \A | \z <ret> ) <a-&> ) <space> <gt> }
try %{ execute-keys -draft x <a-k> ^ \h * (when) $ <ret> <a-semicolon> <a-?> ^ \h * (switch) <ret> s \A | \z <ret> ) <a-&> ) <space> <gt> }
# align _catch_ and _finally_ to _try_
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (catch|finally) $ <ret> <a-semicolon> <a-?> ^ \h * (try) <ret> s \A | \z <ret> ) <a-&> }
try %{ execute-keys -draft x <a-k> ^ \h * (catch|finally) $ <ret> <a-semicolon> <a-?> ^ \h * (try) <ret> s \A | \z <ret> ) <a-&> }
}
}
define-command -hidden moon-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
}
}
@ -111,9 +111,9 @@ define-command -hidden moon-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : moon-trim-indent <ret> }
# indent after start structure
try %{ execute-keys -draft k <a-x> <a-k> ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ <ret> j <a-gt> }
# deindent after return statements
try %{ execute-keys -draft k <a-x> <a-k> ^ \h * (break|return) \b <ret> j <a-lt> }
try %{ execute-keys -draft k x <a-k> ^ \h * (break|return) \b <ret> j <a-lt> }
}
}

View File

@ -19,7 +19,7 @@ hook global WinSetOption filetype=nim %{
hook window InsertChar \n -group nim-insert nim-insert-on-new-line
hook window InsertChar \n -group nim-indent nim-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group nim-trim-indent %{ try %{ exec -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group nim-trim-indent %{ try %{ exec -draft <semicolon> x s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window nim-.+ }
}
@ -114,7 +114,7 @@ add-highlighter shared/nim/code/ regex %{'(\\([rcnlftvabe\\"']|0*[12]?\d?\d|x[0-
define-command -hidden nim-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ exec -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
try %{ exec -draft k x s ^\h*#\h* <ret> y jgh P }
}
}
@ -123,9 +123,9 @@ define-command -hidden nim-indent-on-new-line %{
# preserve previous line indent
try %{ exec -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ exec -draft k <a-x> s \h+$ <ret> d }
try %{ exec -draft k x s \h+$ <ret> d }
# indent after line ending with enum, tuple, object, type, import, export, const, let, var, ':' or '='
try %{ exec -draft <space> k <a-x> <a-k> (:|=|\b(?:enum|tuple|object|const|let|var|import|export|type))$ <ret> j <a-gt> }
try %{ exec -draft <space> k x <a-k> (:|=|\b(?:enum|tuple|object|const|let|var|import|export|type))$ <ret> j <a-gt> }
}
}

View File

@ -20,7 +20,7 @@ hook global WinSetOption filetype=ninja %{
hook window InsertChar \n -group ninja-insert ninja-insert-on-new-line
hook window InsertChar \n -group ninja-indent ninja-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group ninja-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group ninja-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ninja-.+ }
}
@ -82,13 +82,13 @@ evaluate-commands %sh{
define-command -hidden ninja-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden ninja-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
}
}

View File

@ -91,7 +91,7 @@ add-highlighter shared/nix/code/ regex '([^:/?#\s]+):([^#(){}\[\]";`|\s\\]+)' 0:
define-command -hidden nix-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden nix-indent-on-char %<
@ -104,7 +104,7 @@ define-command -hidden nix-indent-on-char %<
define-command -hidden nix-insert-on-new-line %<
evaluate-commands -draft -itersel %<
# copy // comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
>
>
@ -115,9 +115,9 @@ define-command -hidden nix-indent-on-new-line %<
# filter previous line
try %{ execute-keys -draft k : nix-trim-indent <ret> }
# indent after lines beginning / ending with opener token
try %_ execute-keys -draft k <a-x> <a-k> ^\h*[[{]|[[{]$ <ret> j <a-gt> _
try %_ execute-keys -draft k x <a-k> ^\h*[[{]|[[{]$ <ret> j <a-gt> _
# deindent closer token(s) when after cursor
try %_ execute-keys -draft <a-x> <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> _
try %_ execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> _
>
>

View File

@ -192,7 +192,7 @@ EOF
define-command -hidden pascal-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -203,9 +203,9 @@ define-command -hidden pascal-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after certain keywords
try %{ execute-keys -draft k<a-x><a-k>(?i)(asm|begin|const|else|except|exports|finalization|finally|label|of|otherwise|private|property|public|protected|published|record|repeat|resourcestring|threadvar|try|type|uses|var|:)\h*$<ret>j<a-gt> }
try %{ execute-keys -draft kx<a-k>(?i)(asm|begin|const|else|except|exports|finalization|finally|label|of|otherwise|private|property|public|protected|published|record|repeat|resourcestring|threadvar|try|type|uses|var|:)\h*$<ret>j<a-gt> }
}
}
§

View File

@ -17,7 +17,7 @@ hook global WinSetOption filetype=perl %{
set-option window static_words %opt{perl_static_words}
# cleanup trailing whitespaces when exiting insert mode
hook window ModeChange pop:insert:.* -group perl-trim-indent %{ try %{ execute-keys -draft <a-x>s^\h+$<ret>d } }
hook window ModeChange pop:insert:.* -group perl-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } }
hook window InsertChar \n -group perl-insert perl-insert-on-new-line
hook window InsertChar \n -group perl-indent perl-indent-on-new-line
hook window InsertChar \{ -group perl-indent perl-indent-on-opening-curly-brace
@ -110,7 +110,7 @@ add-highlighter shared/perl/code/ regex \$(LAST_REGEXP_CODE_RESULT|LIST_SEPARATO
define-command -hidden perl-insert-on-new-line %~
evaluate-commands -draft -itersel %=
# copy # comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K#\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K#\h* <ret> y<c-o>P<esc> }
=
~
@ -119,17 +119,17 @@ define-command -hidden perl-indent-on-new-line %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> [{(]\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after if|else|while|for
try %[ execute-keys -draft <semicolon><a-F>)MB <a-k> \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z <ret> s \A|.\z <ret> 1<a-&>1<a-space><a-gt> ]
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
=
~

View File

@ -72,7 +72,7 @@ add-highlighter shared/php-file/php region '<\?(php)?' '\?>' ref php
define-command -hidden php-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden php-indent-on-char %<
@ -85,9 +85,9 @@ define-command -hidden php-indent-on-char %<
define-command -hidden php-insert-on-new-line %<
evaluate-commands -draft -itersel %<
# copy // comments or docblock * prefix and following white spaces
try %{ execute-keys -draft s [^/] <ret> k <a-x> s ^\h*\K(?://|[*][^/])\h* <ret> y gh j P }
try %{ execute-keys -draft s [^/] <ret> k x s ^\h*\K(?://|[*][^/])\h* <ret> y gh j P }
# append " * " on lines starting a multiline /** or /* comment
try %{ execute-keys -draft k <a-x> s ^\h*/[*][* ]? <ret> j gi i <space>*<space> }
try %{ execute-keys -draft k x s ^\h*/[*][* ]? <ret> j gi i <space>*<space> }
>
>
@ -98,9 +98,9 @@ define-command -hidden php-indent-on-new-line %<
# filter previous line
try %{ execute-keys -draft k : php-trim-indent <ret> }
# indent after lines beginning / ending with opener token
try %_ execute-keys -draft k <a-x> <a-k> ^\h*[[{]|[[{]$ <ret> j <a-gt> _
try %_ execute-keys -draft k x <a-k> ^\h*[[{]|[[{]$ <ret> j <a-gt> _
# deindent closer token(s) when after cursor
try %_ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> _
try %_ execute-keys -draft x <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> _
>
>

View File

@ -19,7 +19,7 @@ hook global WinSetOption filetype=pony %{
hook window InsertChar \n -group pony-insert pony-insert-on-new-line
hook window InsertChar \n -group pony-indent pony-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group pony-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group pony-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pony-.+ }
}
@ -93,7 +93,7 @@ define-command -hidden pony-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <space> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after line ending with :
try %{ execute-keys -draft <space> k x <a-k> (\b(?:do|try|then|else)|:|=>)$ <ret> j <a-gt> }
# else, end are always de-indented

View File

@ -69,7 +69,7 @@ evaluate-commands %sh{
define-command -hidden protobuf-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -80,13 +80,13 @@ define-command -hidden protobuf-indent-on-newline %~
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with {
try %[ execute-keys -draft k<a-x> <a-k> \{\h*$ <ret> j<a-gt> ]
try %[ execute-keys -draft kx <a-k> \{\h*$ <ret> j<a-gt> ]
# cleanup trailing white spaces on the previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
# copy // comments prefix
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}(\h*(?=\S))? <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K/{2,}(\h*(?=\S))? <ret> y<c-o>P<esc> }
# deindent closing brace(s) when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
]
~

View File

@ -62,7 +62,7 @@ add-highlighter shared/pug/code/ regex ((?:\.[A-Za-z][A-Za-z0-9_-]*
define-command -hidden pug-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden pug-indent-on-new-line %{
@ -72,7 +72,7 @@ define-command -hidden pug-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : pug-trim-indent <ret> }
# copy '//', '|', '-' or '(!)=' prefix and following whitespace
try %{ execute-keys -draft k <a-x> s ^\h*\K[/|!=-]{1,2}\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K[/|!=-]{1,2}\h* <ret> y gh j P }
# indent unless we copied something above
try %{ execute-keys -draft <a-gt> <space> b s \S <ret> g l <a-lt> }
}

View File

@ -94,13 +94,13 @@ add-highlighter shared/purescript/code/ regex ^\s*(?:where\s+|let\s+|default\s+)
define-command -hidden purescript-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden purescript-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
}
}

View File

@ -19,7 +19,7 @@ hook global WinSetOption filetype=python %{
hook window InsertChar \n -group python-insert python-insert-on-new-line
hook window InsertChar \n -group python-indent python-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group python-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook window ModeChange pop:insert:.* -group python-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window python-.+ }
}
@ -149,7 +149,7 @@ add-highlighter shared/python/code/ regex ^\h*(?:from|import)\h+(\S+) 1:module
define-command -hidden python-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P }
}
}
@ -158,11 +158,11 @@ define-command -hidden python-indent-on-new-line %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft k x s \h+$ <ret> d }
# indent after line ending with :
try %{ execute-keys -draft <space> k <a-x> <a-k> :$ <ret> <a-K> ^\h*# <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> :$ <ret> <a-K> ^\h*# <ret> j <a-gt> }
# deindent closing brace/bracket when after cursor (for arrays and dictionaries)
try %< execute-keys -draft <a-x> <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>

View File

@ -56,7 +56,7 @@ add-highlighter shared/r/code/ regex (?<=[\w\s\d'"_)])(\$|@|\^|-|\+|%[^%^\n]+%|\
define-command -hidden r-trim-indent %{
# remove the line if it's empty when leaving the insert mode
try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> d }
try %{ execute-keys -draft x 1s^(\h+)$<ret> d }
}
define-command -hidden r-indent-on-newline %< evaluate-commands -draft -itersel %<
@ -64,26 +64,26 @@ define-command -hidden r-indent-on-newline %< evaluate-commands -draft -itersel
try %<
# if previous line closed a paren (possibly followed by words and a comment),
# copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?(?:#[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
execute-keys -draft kx 1s(\))(\h+\w+)*\h*(\;\h*)?(?:#[^\n]+)?\n\z<ret> m<a-semicolon>J <a-S> 1<a-&>
> catch %<
# else indent new lines with the same level as the previous one
execute-keys -draft K <a-&>
>
# remove previous empty lines resulting from the automatic indent
try %< execute-keys -draft k <a-x> <a-k>^\h+$<ret> Hd >
try %< execute-keys -draft k x <a-k>^\h+$<ret> Hd >
# indent after an opening brace or parenthesis at end of line
try %< execute-keys -draft k <a-x> s[{(]\h*$<ret> j <a-gt> >
try %< execute-keys -draft k x s[{(]\h*$<ret> j <a-gt> >
# indent after a statement not followed by an opening brace
try %< execute-keys -draft k <a-x> s\)\h*(?:#[^\n]+)?\n\z<ret> \
try %< execute-keys -draft k x s\)\h*(?:#[^\n]+)?\n\z<ret> \
<a-semicolon>mB <a-k>\A\b(if|for|while)\b<ret> <a-semicolon>j <a-gt> >
try %< execute-keys -draft k <a-x> s \belse\b\h*(?:#[^\n]+)?\n\z<ret> \
try %< execute-keys -draft k x s \belse\b\h*(?:#[^\n]+)?\n\z<ret> \
j <a-gt> >
# deindent after a single line statement end
try %< execute-keys -draft K <a-x> <a-k>\;\h*(#[^\n]+)?$<ret> \
K <a-x> s\)(\h+\w+)*\h*(#[^\n]+)?\n([^\n]*\n){2}\z<ret> \
try %< execute-keys -draft K x <a-k>\;\h*(#[^\n]+)?$<ret> \
K x s\)(\h+\w+)*\h*(#[^\n]+)?\n([^\n]*\n){2}\z<ret> \
MB <a-k>\A\b(if|for|while)\b<ret> <a-S>1<a-&> >
try %< execute-keys -draft K <a-x> <a-k>\;\h*(#[^\n]+)?$<ret> \
K <a-x> s \belse\b\h*(?:#[^\n]+)?\n([^\n]*\n){2}\z<ret> \
try %< execute-keys -draft K x <a-k>\;\h*(#[^\n]+)?$<ret> \
K x s \belse\b\h*(?:#[^\n]+)?\n([^\n]*\n){2}\z<ret> \
<a-S>1<a-&> >
# align to the opening parenthesis or opening brace (whichever is first)
# on a previous line if its followed by text on the same line
@ -120,10 +120,10 @@ define-command -hidden r-insert-on-newline %[ evaluate-commands -itersel -draft
try %[
evaluate-commands -draft -save-regs '/"' %[
# copy the commenting prefix
execute-keys -save-regs '' k <a-x>1s^\h*(#+\h*)<ret> y
execute-keys -save-regs '' k x1s^\h*(#+\h*)<ret> y
try %[
# if the previous comment isn't empty, create a new one
execute-keys <a-x><a-K>^\h*#+\h*$<ret> j<a-x>s^\h*<ret>P
execute-keys x<a-K>^\h*#+\h*$<ret> jxs^\h*<ret>P
] catch %[
# if there is no text in the previous comment, remove it completely
execute-keys d

View File

@ -50,7 +50,7 @@ add-highlighter shared/ragel/code/ regex \b(action|alnum|alpha|any|ascii|case|cn
define-command -hidden ragel-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden ragel-indent-on-char %<
@ -64,7 +64,7 @@ define-command -hidden ragel-indent-on-char %<
define-command -hidden ragel-insert-on-new-line %<
evaluate-commands -draft -itersel %<
# copy _#_ comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
>
>
@ -75,9 +75,9 @@ define-command -hidden ragel-indent-on-new-line %<
# filter previous line
try %{ execute-keys -draft k : ragel-trim-indent <ret> }
# indent after lines ending with opener token
try %< execute-keys -draft k <a-x> <a-k> [[{(*]$ <ret> j <a-gt> >
try %< execute-keys -draft k x <a-k> [[{(*]$ <ret> j <a-gt> >
# align closer token to its opener when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})\]] <ret> gh / [})\]] <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*[})\]] <ret> gh / [})\]] <ret> m <a-S> 1<a-&> >
>
>

View File

@ -144,7 +144,7 @@ define-command ruby-alternative-file -docstring 'Jump to the alternate file (imp
define-command -hidden ruby-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -153,10 +153,10 @@ define-command -hidden ruby-trim-indent %{
define-command -hidden ruby-indent-on-char %{
evaluate-commands -no-hooks -draft -itersel %{
# align middle and end structures to start
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (else) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (if|case) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (elsif) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (if) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (when) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (case) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft <a-x> <a-k> ^ \h * (rescue) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (begin|def) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^ \h * (else) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (if|case) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^ \h * (elsif) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (if) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^ \h * (when) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (case) <ret> <a-S> 1<a-&> }
try %{ execute-keys -draft x <a-k> ^ \h * (rescue) $ <ret> <a-a> i <a-semicolon> <a-?> ^ \h * (begin|def) <ret> <a-S> 1<a-&> }
}
}
@ -167,23 +167,23 @@ define-command -hidden ruby-indent-on-new-line %{
# filter previous line
try %{ execute-keys -draft k : ruby-trim-indent <ret> }
# indent after start structure
try %{ execute-keys -draft k <a-x> <a-k> ^ \h * (begin|case|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|.+\bdo$|.+\bdo\h\|.+(?=\|)) [^0-9A-Za-z_!?] <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-k> ^ \h * (begin|case|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|.+\bdo$|.+\bdo\h\|.+(?=\|)) [^0-9A-Za-z_!?] <ret> j <a-gt> }
}
}
define-command -hidden ruby-insert-on-new-line %[
evaluate-commands -no-hooks -draft -itersel %[
# copy _#_ comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y jgi P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y jgi P }
# wisely add end structure
evaluate-commands -save-regs x %[
try %{ execute-keys -draft k <a-x> s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %{ execute-keys -draft k x s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %[
evaluate-commands -draft %[
# Check if previous line opens a block
execute-keys -draft k<a-x> <a-k>^<c-r>x(begin|case|class|def|for|if|module|unless|until|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?]<ret>
execute-keys -draft kx <a-k>^<c-r>x(begin|case|class|def|for|if|module|unless|until|while|.+\bdo$|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?]<ret>
# Check that we do not already have an end for this indent level which is first set via `ruby-indent-on-new-line` hook
execute-keys -draft }i J <a-x> <a-K> ^<c-r>x(end|else|elsif|rescue|when)[^0-9A-Za-z_!?]<ret>
execute-keys -draft }i J x <a-K> ^<c-r>x(end|else|elsif|rescue|when)[^0-9A-Za-z_!?]<ret>
]
execute-keys -draft o<c-r>xend<esc> # insert a new line with containing end
]

View File

@ -109,7 +109,7 @@ add-highlighter shared/rust/code/std_traits regex \b(Copy|Send|Sized
define-command -hidden rust-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden rust-indent-on-new-line %~
@ -118,10 +118,10 @@ define-command -hidden rust-indent-on-new-line %~
try %[ # line comment
evaluate-commands -draft -save-regs '/"' %[
# copy the commenting prefix
execute-keys -save-regs '' k <a-x> s ^\h*//[!/]{0,2}\h* <ret> y
execute-keys -save-regs '' k x s ^\h*//[!/]{0,2}\h* <ret> y
try %[
# if the previous comment isn't empty, create a new one
execute-keys <a-x><a-K>^\h*//[!/]{0,2}$<ret> j<a-x>s^\h*<ret>P
execute-keys x<a-K>^\h*//[!/]{0,2}$<ret> jxs^\h*<ret>P
] catch %[
# TODO figure out a way to not delete empty comment in current line
# if there is no space and text in the previous comment, remove it completely
@ -130,24 +130,24 @@ define-command -hidden rust-indent-on-new-line %~
]
] catch %[ # block comment
# if the previous line isn't within a comment scope, break
execute-keys -draft k<a-x> <a-k>^(\h*/\*|\h+\*(?!/))<ret>
execute-keys -draft kx <a-k>^(\h*/\*|\h+\*(?!/))<ret>
# find comment opening, validate it was not closed, and check its using star prefixes
execute-keys -draft <a-?>/\*<ret><a-H> <a-K>\*/<ret> <a-k>\A\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\z<ret>
try %[
# if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft kx<a-k>^\h*/\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the next line is a comment line insert a star
execute-keys -draft j<a-x><a-k>^\h+\*<ret>
execute-keys -draft jx<a-k>^\h+\*<ret>
execute-keys -draft i*<space><esc>
] catch %[
try %[
# if the previous line is an empty comment line, close the comment scope
execute-keys -draft k<a-x><a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
execute-keys -draft kx<a-k>^\h+\*\h+$<ret> x1s\*(\h*)<ret>c/<esc>
] catch %[
# if the previous line is a non-empty comment line, add a star
execute-keys -draft i*<space><esc>
@ -158,29 +158,29 @@ define-command -hidden rust-indent-on-new-line %~
# trim trailing whitespace on the previous line
try %[ execute-keys -draft s\h+$<ret> d ]
# align the new star with the previous one
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
execute-keys Kx1s^[^*]*(\*)<ret>&
]
} catch %`
# re-indent previous line if it starts with where to match previous block
# string literal parsing within extern does not handle escape
try %% execute-keys -draft k <a-x> <a-k> ^\h*where\b <ret> hh <a-?> ^\h*\b(impl|((|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )((async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union)))\b <ret> <a-S> 1<a-&> %
try %% execute-keys -draft k x <a-k> ^\h*where\b <ret> hh <a-?> ^\h*\b(impl|((|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )((async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union)))\b <ret> <a-S> 1<a-&> %
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# indent after lines ending with [{([].+ and move first parameter to own line
try %< execute-keys -draft [c[({[],[)}\]] <ret> <a-k> \A[({[][^\n]+\n[^\n]*\n?\z <ret> L i<ret><esc> <gt> <a-S> <a-&> >
# indent after non-empty lines not starting with operator and not ending with , or ; or {
# XXX simplify this into a single <a-k> without s
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>{](\h*/[/*].*|)$ <ret> j <a-gt> >
try %< execute-keys -draft k x s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>{](\h*/[/*].*|)$ <ret> j <a-gt> >
# indent after lines ending with {
try %+ execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> +
try %+ execute-keys -draft k x <a-k> \{$ <ret> j <a-gt> +
# dedent after lines starting with . and ending with } or ) or , or ; or .await (} or ) or .await maybe with ?)
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\. <ret> <a-k> ([,<semicolon>]|(([})]|\.await)\?*))\h*$ <ret> j <a-lt> _
try %_ execute-keys -draft k x <a-k> ^\h*\. <ret> <a-k> ([,<semicolon>]|(([})]|\.await)\?*))\h*$ <ret> j <a-lt> _
# dedent after lines ending with " => {}" - part of empty match
try %# execute-keys -draft k <a-x> <a-k> \ =>\ \{\}\h*$ <ret> j <a-lt> #
try %# execute-keys -draft k x <a-k> \ =>\ \{\}\h*$ <ret> j <a-lt> #
# align to opening curly brace or paren when newline is inserted before a single closing
try %< execute-keys -draft <a-h> <a-k> ^\h*[)}] <ret> h m <a-S> 1<a-&> >
# todo dedent additional unmatched parenthesis
# try %& execute-keys -draft k <a-x> s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{
# try %& execute-keys -draft k x s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{
# count previous selections length
# printf "j $(echo $kak_selections_length | wc -w) <a-lt>"
# } &
@ -195,7 +195,7 @@ define-command -hidden rust-indent-on-opening-curly-brace %[
# align indent with opening paren when { is entered on a new line after the closing paren
try %[ execute-keys -draft h <a-F> ) M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
# dedent standalone { after impl and related block without any { in between
try %@ execute-keys -draft hh <a-?> ^\h*\b(impl|((|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )((async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union))|if|for)\b <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> @
try %@ execute-keys -draft hh <a-?> ^\h*\b(impl|((|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )((async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union))|if|for)\b <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll x <a-k> ^\h*\{$ <ret> <a-lt> @
~
]

View File

@ -53,7 +53,7 @@ add-highlighter shared/sass/code/ regex !important 0:keyword
define-command -hidden sass-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden sass-indent-on-closing-brace %<
@ -66,7 +66,7 @@ define-command -hidden sass-indent-on-closing-brace %<
define-command -hidden sass-insert-on-new-line %<
evaluate-commands -draft -itersel %<
# copy // comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K/{2,}\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K/{2,}\h* <ret> y gh j P }
>
>
@ -77,9 +77,9 @@ define-command -hidden sass-indent-on-new-line %<
# filter previous line
try %{ execute-keys -draft k : sass-trim-indent <ret> }
# avoid indent after properties and comments
try %{ execute-keys -draft k <a-x> <a-K> [:/] <ret> j <a-gt> }
try %{ execute-keys -draft k x <a-K> [:/] <ret> j <a-gt> }
# deindent closing brace when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
>
>

View File

@ -57,13 +57,13 @@ add-highlighter shared/scala/code/ regex (\[|\]|=>|<:|:>|=:=|::|&&|\|\|) 0:opera
define-command -hidden scala-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden scala-insert-on-new-line %[
evaluate-commands -draft -itersel %[
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K#\h* <ret> y<c-o>P<esc> }
try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K#\h* <ret> y<c-o>P<esc> }
]
]
@ -74,9 +74,9 @@ define-command -hidden scala-indent-on-new-line %[
# filter previous line
try %[ execute-keys -draft k : scala-trim-indent <ret> ]
# indent after lines ending with {
try %[ execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> ]
try %[ execute-keys -draft k x <a-k> \{$ <ret> j <a-gt> ]
# deindent closing brace when after cursor
try %[ execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
try %[ execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ]
]
]

View File

@ -71,7 +71,7 @@ add-highlighter shared/sh/double_string/expansion regex (?<!\\)(?:\\\\)*\K\$(\w+
define-command -hidden sh-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
# This is at best an approximation, since shell syntax is very complex.
@ -85,7 +85,7 @@ define-command -hidden sh-trim-indent %{
define-command -hidden sh-insert-on-new-line %[
evaluate-commands -draft -itersel %[
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
]
]
@ -120,11 +120,11 @@ define-command -hidden sh-indent-on-new-line %¶
# done
#
# indent after do
try %{ execute-keys -draft <space> k <a-x> <a-k> \bdo$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> \bdo$ <ret> j <a-gt> }
# copy the indentation of the matching for/when - matching on the do
# statement, so we don't need to duplicate this for the two loop
# structures.
try %{ execute-keys -draft <space> k <a-x> <a-k> \bdone$ <ret> gh [c\bdo\b,\bdone\b <ret> <a-x> <a-S> 1<a-&> <space> j K <a-&> }
try %{ execute-keys -draft <space> k x <a-k> \bdone$ <ret> gh [c\bdo\b,\bdone\b <ret> x <a-S> 1<a-&> <space> j K <a-&> }
# Indent if/then/else syntax, e.g.:
# if [ $foo = $bar ]; then
@ -142,11 +142,11 @@ define-command -hidden sh-indent-on-new-line %¶
# fi
#
# indent after then
try %{ execute-keys -draft <space> k <a-x> <a-k> \bthen$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> \bthen$ <ret> j <a-gt> }
# copy the indentation of the matching if
try %{ execute-keys -draft <space> k <a-x> <a-k> \bfi$ <ret> gh [c\bif\b,\bfi\b <ret> <a-x> <a-S> 1<a-&> <space> j K <a-&> }
try %{ execute-keys -draft <space> k x <a-k> \bfi$ <ret> gh [c\bif\b,\bfi\b <ret> x <a-S> 1<a-&> <space> j K <a-&> }
# copy the indentation of the matching if, and then re-indent afterwards
try %{ execute-keys -draft <space> k <a-x> <a-k> \belse$ <ret> gh [c\bif\b,\bfi\b <ret> <a-x> <a-S> 1<a-&> <space> j K <a-&> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> \belse$ <ret> gh [c\bif\b,\bfi\b <ret> x <a-S> 1<a-&> <space> j K <a-&> j <a-gt> }
# Indent case syntax, e.g.:
# case "$foo" in
@ -166,13 +166,13 @@ define-command -hidden sh-indent-on-new-line %¶
# esac
#
# indent after in
try %{ execute-keys -draft <space> k <a-x> <a-k> \bin$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> \bin$ <ret> j <a-gt> }
# copy the indentation of the matching case
try %{ execute-keys -draft <space> k <a-x> <a-k> \besac$ <ret> gh [c\bcase\b,\besac\b <ret> <a-x> <a-S> 1<a-&> <space> j K <a-&> }
try %{ execute-keys -draft <space> k x <a-k> \besac$ <ret> gh [c\bcase\b,\besac\b <ret> x <a-S> 1<a-&> <space> j K <a-&> }
# indent after )
try %{ execute-keys -draft <space> k <a-x> <a-k> ^\s*\(?[^(]+[^)]\)$ <ret> j <a-gt> }
try %{ execute-keys -draft <space> k x <a-k> ^\s*\(?[^(]+[^)]\)$ <ret> j <a-gt> }
# deindent after ;;
try %{ execute-keys -draft <space> k <a-x> <a-k> ^\s*\;\;$ <ret> j <a-lt> }
try %{ execute-keys -draft <space> k x <a-k> ^\s*\;\;$ <ret> j <a-lt> }
# Indent compound commands as logical blocks, e.g.:
# {
@ -194,11 +194,11 @@ define-command -hidden sh-indent-on-new-line %¶
# white space (including a newline), though technically it can also be
# ';'. Only vertical white space makes sense in this context, though,
# since the syntax denotes a logical block, not a simple compound command.
try %= execute-keys -draft <space> k <a-x> <a-k> (\s|^)\{$ <ret> j <a-gt> =
try %= execute-keys -draft <space> k x <a-k> (\s|^)\{$ <ret> j <a-gt> =
# deindent closing }
try %= execute-keys -draft <space> k <a-x> <a-k> ^\s*\}$ <ret> <a-lt> j K <a-&> =
try %= execute-keys -draft <space> k x <a-k> ^\s*\}$ <ret> <a-lt> j K <a-&> =
# deindent closing } when after cursor
try %= execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> =
try %= execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> =
@

View File

@ -43,7 +43,7 @@ add-highlighter shared/taskpaper/ regex (([a-z]+://\S+)|((mailto:)[\w+-]+@\S+))
define-command -hidden taskpaper-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
execute-keys <a-x>
execute-keys x
# remove trailing white spaces
try %{ execute-keys -draft s \h + $ <ret> d }
}
@ -54,9 +54,9 @@ define-command -hidden taskpaper-indent-on-new-line %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
## If the line above is a project indent with a tab
try %{ execute-keys -draft Z k<a-x> <a-k>^\h*([^:\n]+):<ret> z i<tab> }
try %{ execute-keys -draft Z kx <a-k>^\h*([^:\n]+):<ret> z i<tab> }
# cleanup trailing white spaces on previous line
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
try %{ execute-keys -draft kx s \h+$ <ret>d }
}
}

View File

@ -54,13 +54,13 @@ add-highlighter shared/toml/code/ regex \
define-command -hidden toml-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden toml-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy # comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
}
}

View File

@ -80,7 +80,7 @@ define-command -hidden twig-insert-on-new-line %[
evaluate-commands -draft -itersel %/
execute-keys <semicolon>
try %[
execute-keys -draft k<a-x><a-k>^\h*\{\[%#\{\]\h+$<ret>
execute-keys -draft kx<a-k>^\h*\{\[%#\{\]\h+$<ret>
execute-keys -draft jghd
]
/

View File

@ -13,7 +13,7 @@ hook global WinSetOption filetype=vhdl %[
hook -group vhdl-indent window InsertChar \) vhdl-indent-on-closing-parenthesis
hook -group vhdl-insert window InsertChar \n vhdl-insert-on-new-line
# Cleanup trailing whitespaces on current line insert end.
hook -group vhdl-trim-indent window ModeChange pop:insert:.* %[ try %[ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d ] ]
hook -group vhdl-trim-indent window ModeChange pop:insert:.* %[ try %[ execute-keys -draft <semicolon> x s ^\h+$ <ret> d ] ]
hook -once -always window WinSetOption filetype=.* %[ remove-hooks window vhdl-.+ ]
]
@ -168,13 +168,13 @@ define-command -hidden vhdl-insert-on-new-line %[
# Copy '--' comment prefix and following white spaces.
try %[
# <a-lt> is needed because of "Preserve previous line indent" command.
try %[ execute-keys -draft k <a-x> s ^\h*--\h* <ret> y j <a-lt> gh P ]
try %[ execute-keys -draft k x s ^\h*--\h* <ret> y j <a-lt> gh P ]
]
]
evaluate-commands -save-regs x %[
# Save previous line indent in register x.
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft kxs^\h+<ret>"xy ] catch %[ reg x '' ]
# All "wisely add" commands share the same concept.
# Only "end if" has extra comments.
@ -182,170 +182,170 @@ define-command -hidden vhdl-insert-on-new-line %[
evaluate-commands %[
try %[
# Validate previous line and that it is not closed yet.
execute-keys -draft k<a-x> <a-k>^\h*(?i)((then|(.*:\h*)?if\b.*\bthen)$)<ret> }i<a-x> <a-K>^<c-r>x(?i)end\b<ret>
execute-keys -draft kx <a-k>^\h*(?i)((then|(.*:\h*)?if\b.*\bthen)$)<ret> }ix <a-K>^<c-r>x(?i)end\b<ret>
# Don't add for "if ... generate", it requires "end generate;".
execute-keys -draft k<a-x> <a-K>(?i)\bgenerate\b<ret>
execute-keys -draft kx <a-K>(?i)\bgenerate\b<ret>
execute-keys -draft o<c-r>xend<space>if<semicolon><esc>
]
]
# Wisely add "end generate;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i).*\bgenerate$<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^\h*(?i).*\bgenerate$<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
# Don't add in case of comment line.
execute-keys -draft k<a-x> <a-K>^\h*--<ret>
execute-keys -draft kx <a-K>^\h*--<ret>
execute-keys -draft o<c-r>xend<space>generate<semicolon><esc>
]
]
# Wisely add "end case;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(case|.*\h*:\h*case)\b<ret> }i<a-x> <a-K>^<c-r>x(?i)end<ret>
execute-keys -draft kx <a-k>^\h*(?i)(case|.*\h*:\h*case)\b<ret> }ix <a-K>^<c-r>x(?i)end<ret>
execute-keys -draft o<c-r>xend<space>case<semicolon><esc>
]
]
# Wisely add "begin" and "end block;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)((block|.*:\h*block)\b)<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^\h*(?i)((block|.*:\h*block)\b)<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>block<semicolon><esc>
]
]
# Wisely add "begin" and "end process;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(.*:\h*)?(postponed\h+)?process\b<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^\h*(?i)(.*:\h*)?(postponed\h+)?process\b<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>process<semicolon><esc>
]
]
# Wisely add "end loop;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(.*\bloop|.*\h*:\h*(for|loop))$<ret> }i<a-x> <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft kx <a-k>^\h*(?i)(.*\bloop|.*\h*:\h*(for|loop))$<ret> }ix <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft o<c-r>xend<space>loop<semicolon><esc>
]
]
# Wisely add "end protected;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(type\b.*\bis\h+protected)$<ret> }i<a-x> <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+protected)$<ret> }ix <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft o<c-r>xend<space>protected<semicolon><esc>
]
]
# Wisely add "end protected body;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)(\h*type\h+\w+\h+is\h+protected\h+body$)<ret> }i<a-x> <a-K>^<c-r>x(?i)end\h+protected\h+body\b<ret>
execute-keys -draft kx <a-k>^(?i)(\h*type\h+\w+\h+is\h+protected\h+body$)<ret> }ix <a-K>^<c-r>x(?i)end\h+protected\h+body\b<ret>
execute-keys -draft o<c-r>xend<space>protected<space>body<semicolon><esc>
]
]
# Wisely add "end record;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(type\b.*\bis\h+record\h*)$<ret> }i<a-x> <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+record\h*)$<ret> }ix <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft o<c-r>xend<space>record<semicolon><esc>
]
]
# Wisely add ");" for "type ... is (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(type\b.*\bis\h+\(\h*)$<ret> }i<a-x> <a-K>^<c-r>x(\))<ret>
execute-keys -draft kx <a-k>^\h*(?i)(type\b.*\bis\h+\(\h*)$<ret> }ix <a-K>^<c-r>x(\))<ret>
execute-keys -draft o<c-r>x)<semicolon><esc>
]
]
# Wisely add "end entity;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)\h*entity\b.*\bis$<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^(?i)\h*entity\b.*\bis$<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xend<space>entity<semicolon><esc>
]
]
# Wisely add "begin" and "end function;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)(\h*\)?\h*return\b.*\bis$)<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^(?i)(\h*\)?\h*return\b.*\bis$)<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>function<semicolon><esc>
]
try %[
execute-keys -draft k<a-x> <a-k>^(?i)(\h*((pure|impure)\h+)?function\b.*\bis$)<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^(?i)(\h*((pure|impure)\h+)?function\b.*\bis$)<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>function<semicolon><esc>
]
]
# Wisely add "begin" and "end procedure;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)(\h*procedure\b.*\bis$)<ret> }i<a-x> <a-K>^<c-r>x(?i)\b(begin|end)\b<ret>
execute-keys -draft kx <a-k>^(?i)(\h*procedure\b.*\bis$)<ret> }ix <a-K>^<c-r>x(?i)\b(begin|end)\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>procedure<semicolon><esc>
]
try %[
execute-keys -draft k<a-x> <a-k>^(?i)\h*\)\h*\bis$<ret> }i<a-x> <a-K>^<c-r>x(?i)\b(begin|end)\b<ret>
execute-keys -draft kx <a-k>^(?i)\h*\)\h*\bis$<ret> }ix <a-K>^<c-r>x(?i)\b(begin|end)\b<ret>
# Verify that line with opening parenthesis contains "procedure" keyword.
execute-keys -draft k<a-x> s\)<ret> <a-m><semicolon> <a-x><a-k> (?i)\bprocedure\b<ret>
execute-keys -draft kx s\)<ret> <a-m><semicolon> x<a-k> (?i)\bprocedure\b<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>procedure<semicolon><esc>
]
]
# Wisely add "end package;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)(package\b)<ret> }i<a-x> <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft kx <a-k>^(?i)(package\b)<ret> }ix <a-K>^<c-r>x(?i)(end)<ret>
# Make sure it is not package body.
execute-keys -draft k<a-x><a-K>(?i)\bbody\b<ret>
execute-keys -draft kx<a-K>(?i)\bbody\b<ret>
execute-keys -draft oend<space>package<semicolon><esc>
]
]
# Wisely add "end package body;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)(package\h+body\b)<ret> }i<a-x> <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft kx <a-k>^(?i)(package\h+body\b)<ret> }ix <a-K>^<c-r>x(?i)(end)<ret>
execute-keys -draft oend<space>package<space>body<semicolon><esc>
]
]
# Wisely add "begin" and "end architecture;".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^(?i)\h*architecture\b<ret> }i<a-x> <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft kx <a-k>^(?i)\h*architecture\b<ret> }ix <a-K>^<c-r>x(?i)(begin|end)<ret>
execute-keys -draft o<c-r>xbegin<ret><c-r>xend<space>architecture<semicolon><esc>
]
]
# Wisely add ");" for "port (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)port\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft kx <a-k>^\h*(?i)port\h*\($<ret> }ix <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc>
]
]
# Wisely add ");" for "port map (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)port\h+map\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft kx <a-k>^\h*(?i)port\h+map\h*\($<ret> }ix <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc>
]
]
# Wisely add ");" for "generic (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)generic\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft kx <a-k>^\h*(?i)generic\h*\($<ret> }ix <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc>
]
]
# Wisely add ")" for "generic map (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)generic\h+map\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\))<ret>
execute-keys -draft kx <a-k>^\h*(?i)generic\h+map\h*\($<ret> }ix <a-K>^<c-r>x(\))<ret>
execute-keys -draft o<c-r>x)<esc>
]
]
# Wisely add ") return ;" for "[pure|impure] function ... (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)(pure\b|impure\b)?\h*function\b.*\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\)\h*return.*)<ret>
execute-keys -draft kx <a-k>^\h*(?i)(pure\b|impure\b)?\h*function\b.*\h*\($<ret> }ix <a-K>^<c-r>x(\)\h*return.*)<ret>
execute-keys -draft o<c-r>x)<space>return<space><semicolon><esc>
]
]
# Wisely add ");" for "procedure ... (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)procedure\b.*\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\)\h*\;)<ret>
execute-keys -draft kx <a-k>^\h*(?i)procedure\b.*\h*\($<ret> }ix <a-K>^<c-r>x(\)\h*\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc>
]
]
@ -357,9 +357,9 @@ define-command -hidden vhdl-indent-on-new-line %{
# Align "then" to previous "if|elsif".
evaluate-commands -itersel -save-regs x %[
try %[
execute-keys -draft k <a-x> <a-k> (?i)^\h*then$ <ret>
try %[ execute-keys -draft <a-/>(?i)\b(if|elsif)\b<ret><a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft k <a-x>s^\h+<ret>d ] catch %[ ]
execute-keys -draft k x <a-k> (?i)^\h*then$ <ret>
try %[ execute-keys -draft <a-/>(?i)\b(if|elsif)\b<ret>xs^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft k xs^\h+<ret>d ] catch %[ ]
execute-keys -draft kgh i<c-r>x<esc>
]
]
@ -367,9 +367,9 @@ define-command -hidden vhdl-indent-on-new-line %{
# Align "generate" to previous "if|for".
evaluate-commands -itersel -save-regs x %[
try %[
execute-keys -draft k <a-x> <a-k> (?i)^\h*generate$ <ret>
try %[ execute-keys -draft <a-/>(?i)\b(if|for)\b<ret><a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft k <a-x>s^\h+<ret>d ] catch %[ ]
execute-keys -draft k x <a-k> (?i)^\h*generate$ <ret>
try %[ execute-keys -draft <a-/>(?i)\b(if|for)\b<ret>xs^\h+<ret>"xy ] catch %[ reg x '' ]
try %[ execute-keys -draft k xs^\h+<ret>d ] catch %[ ]
execute-keys -draft kgh i<c-r>x<esc>
]
]
@ -378,38 +378,38 @@ define-command -hidden vhdl-indent-on-new-line %{
try %[ execute-keys -draft <semicolon> K <a-&> ]
# Cleanup trailing whitespaces from previous line.
try %[ execute-keys -draft k <a-x> s \h+$ <ret> d ]
try %[ execute-keys -draft k x s \h+$ <ret> d ]
# Increase indent after some keywords.
try %[
execute-keys -draft k<a-x><a-k> (?i)\b(begin|block|body|else|for|generate|if|is|loop|process|protected|record|select|then)$ <ret>
execute-keys -draft kx<a-k> (?i)\b(begin|block|body|else|for|generate|if|is|loop|process|protected|record|select|then)$ <ret>
# Does not indent if in comment line.
execute-keys -draft k<a-x><a-K>(?i)^\h*--<ret>
execute-keys -draft kx<a-K>(?i)^\h*--<ret>
# Handle case line in a bit different way.
execute-keys -draft k<a-x><a-K>(?i)^\h*case\b<ret>
execute-keys -draft kx<a-K>(?i)^\h*case\b<ret>
execute-keys -draft <semicolon> <a-gt>
]
# Add "when " and increase indent after "case ... is".
try %[
execute-keys -draft k<a-x><a-k> (?i)\h*case\b.*\h+is$ <ret>
execute-keys -draft kx<a-k> (?i)\h*case\b.*\h+is$ <ret>
# Don't indent if in comment line.
execute-keys -draft k<a-x><a-K>(?i)^\h*--<ret>
execute-keys -draft kx<a-K>(?i)^\h*--<ret>
execute-keys -draft <semicolon>iwhen<space><esc><a-gt>
]
# Copy the indentation of the matching if.
try %{ execute-keys -draft <space> k <a-x> <a-k> ^\h*(elsif\b|else$) <ret> gh [c^\h*(\S*\h*:\h*)?if\b,\bend\sif\b <ret> <a-x> <a-S> 1<a-&> <space> j K <a-&> }
try %{ execute-keys -draft <space> k x <a-k> ^\h*(elsif\b|else$) <ret> gh [c^\h*(\S*\h*:\h*)?if\b,\bend\sif\b <ret> x <a-S> 1<a-&> <space> j K <a-&> }
# Increase indent after some operators.
try %[ execute-keys -draft <semicolon> <space> k <a-x> <a-k> (\(|=>|<=|:=)$ <ret> j <a-gt> ]
try %[ execute-keys -draft <semicolon> <space> k x <a-k> (\(|=>|<=|:=)$ <ret> j <a-gt> ]
}
}
define-command vhdl-indent-on-closing-parenthesis %[
evaluate-commands -itersel %[
# Decrease indent after ")" at the beginning of line.
try %[ execute-keys -draft <a-x> <a-k> (^\h+\)$) <ret> <a-lt> ]
try %[ execute-keys -draft x <a-k> (^\h+\)$) <ret> <a-lt> ]
]
]

View File

@ -47,13 +47,13 @@ add-highlighter shared/yaml/code/ regex ^\h*-?\h*(\S+): 1:attribute
define-command -hidden yaml-trim-indent %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden yaml-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
}
}

View File

@ -97,13 +97,13 @@ add-highlighter shared/zig/code/ regex "@(?:addWithOverflow|alignCast|alignOf|as
define-command -hidden zig-trim-indent %{
# delete trailing whitespace
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
}
define-command -hidden zig-insert-on-new-line %<
evaluate-commands -draft -itersel %<
# copy // or /// comments prefix or \\ string literal prefix and following whitespace
try %< execute-keys -draft k <a-x> s ^\h*\K(///?|\\\\)\h* <ret> y gh j P >
try %< execute-keys -draft k x s ^\h*\K(///?|\\\\)\h* <ret> y gh j P >
>
>
@ -113,11 +113,11 @@ define-command -hidden zig-indent-on-new-line %<
try %< execute-keys -draft <semicolon> K <a-&> >
try %<
# only if we didn't copy a comment or multiline string
execute-keys -draft <a-x> <a-K> ^\h*(//|\\\\) <ret>
execute-keys -draft x <a-K> ^\h*(//|\\\\) <ret>
# indent after lines ending in {
try %< execute-keys -draft k <a-x> <a-k> \{\h*$ <ret> j <a-gt> >
try %< execute-keys -draft k x <a-k> \{\h*$ <ret> j <a-gt> >
# deindent closing } when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> >
try %< execute-keys -draft x <a-k> ^\h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> >
>
# filter previous line
try %< execute-keys -draft k : zig-trim-indent <ret> >

View File

@ -13,7 +13,7 @@ declare-option -docstring %{
define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m' %{
try %{
## if the line isn't too long, do nothing
execute-keys -draft "<a-x><a-k>^[^\n]{%opt{autowrap_column},}[^\n]<ret>"
execute-keys -draft "x<a-k>^[^\n]{%opt{autowrap_column},}[^\n]<ret>"
try %{
reg m "%val{selections_desc}"
@ -30,7 +30,7 @@ define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m'
| sed "s/%c/${kak_opt_autowrap_column}/g")
printf %s "
evaluate-commands -draft %{
execute-keys '<a-]>p<a-x><a-j>|${format_cmd}<ret>'
execute-keys '<a-]>px<a-j>|${format_cmd}<ret>'
try %{ execute-keys s\h+$<ret> d }
}
select '${kak_main_reg_m}'

View File

@ -43,7 +43,7 @@ declare-option -docstring "name of the client in which all source code jumps wil
define-command -hidden grep-jump %{
evaluate-commands %{ # use evaluate-commands to ensure jumps are collapsed
try %{
execute-keys '<a-x>s^((?:\w:)?[^:]+):(\d+):(\d+)?<ret>'
execute-keys 'xs^((?:\w:)?[^:]+):(\d+):(\d+)?<ret>'
set-option buffer grep_current_line %val{cursor_line}
evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing %reg{1} %reg{2} %reg{3}
try %{ focus %opt{jumpclient} }

View File

@ -48,6 +48,7 @@ struct {
"» pipe commands do not append final end-of-lines anymore\n"
"» {+u}complete-command{} to configure command completion\n"
"» {+b}!{} and {+b}<a-!>{} now select the inserted text\n"
"» {+b}x{} now uses {+b}<a-x>{} behaviour\n"
}, {
20211107,
"» colored and curly underlines support (undocumented in 20210828)\n"

View File

@ -2294,10 +2294,8 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
{ {alt('h')}, {"select to line begin", repeated<select<SelectMode::Replace, select_to_line_begin<false>>>} },
{ {alt('H')}, {"extend to line begin", repeated<select<SelectMode::Extend, select_to_line_begin<false>>>} },
{ {'x'}, {"select line", repeated<select<SelectMode::Replace, select_line>>} },
{ {'X'}, {"extend line", repeated<select<SelectMode::Extend, select_line>>} },
{ {alt('x')}, {"extend selections to whole lines", select<SelectMode::Replace, select_lines>} },
{ {alt('X')}, {"crop selections to whole lines", select<SelectMode::Replace, trim_partial_lines>} },
{ {'x'}, {"extend selections to whole lines", select<SelectMode::Replace, select_lines>} },
{ {alt('x')}, {"crop selections to whole lines", select<SelectMode::Replace, trim_partial_lines>} },
{ {'m'}, {"select to matching character", select<SelectMode::Replace, select_matching<true>>} },
{ {alt('m')}, {"backward select to matching character", select<SelectMode::Replace, select_matching<false>>} },

View File

@ -173,19 +173,6 @@ select_word(const Context& context, const Selection& selection,
template Optional<Selection> select_word<WordType::Word>(const Context&, const Selection&, int, ObjectFlags);
template Optional<Selection> select_word<WordType::WORD>(const Context&, const Selection&, int, ObjectFlags);
Optional<Selection>
select_line(const Context& context, const Selection& selection)
{
auto& buffer = context.buffer();
auto line = selection.cursor().line;
// Next line if line fully selected
if (selection.anchor() <= BufferCoord{line, 0_byte} and
selection.cursor() == BufferCoord{line, buffer[line].length() - 1} and
line != buffer.line_count() - 1)
++line;
return Selection{{line, 0_byte}, {line, buffer[line].length() - 1, max_column}};
}
template<bool only_move>
Optional<Selection>
select_to_line_end(const Context& context, const Selection& selection)

View File

@ -1 +1 @@
jXXXXX:comment-line<ret>
jGex:comment-line<ret>

View File

@ -1 +1 @@
<a-x>
x

View File

@ -1 +0,0 @@
X

View File

@ -1 +0,0 @@
foo

View File

@ -1,2 +0,0 @@
'foo
'

View File

@ -1 +1 @@
<a-X>
<a-x>