1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 12:36:11 +03:00

Support aligning to opening { as well as ( in c-family indent

This commit is contained in:
Maxime Coste 2017-05-20 10:49:56 +01:00
parent b440d9f537
commit cab0adaa53
9 changed files with 31 additions and 11 deletions

View File

@ -28,26 +28,27 @@ def -hidden c-family-trim-autoindent %[ eval -draft -itersel %[
try %[ exec <a-x> 1s^(\h+)$<ret> d ]
] ]
def -hidden c-family-indent-on-newline %[ eval -draft -itersel %[
def -hidden c-family-indent-on-newline %< eval -draft -itersel %<
exec \;
try %[
try %<
# if previous line closed a paren, copy indent of the opening paren line
exec -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?$<ret> m<a-\;>J s\`|.\'<ret> 1<a-&>
] catch %[
> catch %<
# else indent new lines with the same level as the previous one
exec -draft K <a-&>
]
>
# remove previous empty lines resulting from the automatic indent
try %[ exec -draft k <a-x> <a-k>^\h+$<ret> Hd ]
try %< exec -draft k <a-x> <a-k>^\h+$<ret> Hd >
# indent after an opening brace
try %[ exec -draft k <a-x> s\{\h*$<ret> j <a-gt> ]
try %< exec -draft k <a-x> s\{\h*$<ret> j <a-gt> >
# indent after a label
try %[ exec -draft k <a-x> s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> ]
try %< exec -draft k <a-x> s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
# indent after a statement not followed by an opening brace
try %[ exec -draft k <a-x> <a-k>\b(if|else|for|while)\h*\(.+?\)\h*$<ret> j <a-gt> ]
# align to the opening parenthesis on a previous line if its followed by text on the same line
try %[ exec -draft {b <a-k>\`\([^\n]+\n[^\n]*\n?\'<ret> L s\`|.\'<ret> & ]
] ]
try %< exec -draft k <a-x> <a-k>\b(if|else|for|while)\h*\(.+?\)\h*$<ret> j <a-gt> >
# align to the opening parenthesis or opening bracket (whichever is first)
# on a previous line if its followed by text on the same line
try %< exec -draft [b Z<a-\;>[B<a-z><gt> <a-k>\`[{(][^\n]+\n[^\n]*\n?\'<ret> L s\`|.\'<ret> & >
> >
def -hidden c-family-indent-on-opening-curly-brace %[
# align indent with opening paren when { is entered on a new line after the closing paren

View File

@ -0,0 +1 @@
c<ret><esc>

View File

@ -0,0 +1 @@
MyObject obj{param1,%( )param2};

View File

@ -0,0 +1,2 @@
MyObject obj{param1,
param2};

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/core/c-family.kak"
set buffer filetype cpp

View File

@ -0,0 +1 @@
c<ret>qux<esc>

View File

@ -0,0 +1,3 @@
foo{bar(baz,%( )
foo(bar{baz,%( )

View File

@ -0,0 +1,5 @@
foo{bar(baz,
qux
foo(bar{baz,
qux

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/core/c-family.kak"
set buffer filetype cpp