diff options
| author | Maxime Coste <mawww@kakoune.org> | 2022-03-17 09:20:07 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2022-07-05 08:43:40 +1000 |
| commit | ef8a11b3dbefb8a1222974a8c34e15fa006d56e0 (patch) | |
| tree | e66d71d0a5d67c6bc43d4d5977b8468d0335b62d /rc/filetype/javascript.kak | |
| parent | 046be3b06ce41922e363c742ee9470f0ac885d4b (diff) | |
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
Diffstat (limited to 'rc/filetype/javascript.kak')
| -rw-r--r-- | rc/filetype/javascript.kak | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/rc/filetype/javascript.kak b/rc/filetype/javascript.kak index 2f55540a..1f39aa6a 100644 --- a/rc/filetype/javascript.kak +++ b/rc/filetype/javascript.kak @@ -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 %< |
