c-indent: Tweak implementation of c-family-insert-on-newline

This commit is contained in:
Maxime Coste 2016-08-05 09:37:25 +01:00
parent 19e36425f4
commit 967a55d09f

View File

@ -76,7 +76,7 @@ def -hidden _c-family-insert-on-closing-curly-brace %[
try %[ exec -itersel -draft hm<a-x>B<a-x><a-k>^\h*(class|struct|union)<ret> a\;<esc> ] try %[ exec -itersel -draft hm<a-x>B<a-x><a-k>^\h*(class|struct|union)<ret> a\;<esc> ]
] ]
def -hidden _c-family-insert-on-newline %[ def -hidden _c-family-insert-on-newline %[ eval -draft %[
exec \; exec \;
try %[ try %[
eval -draft %[ eval -draft %[
@ -92,38 +92,33 @@ def -hidden _c-family-insert-on-newline %[
] ]
] ]
try %[ try %[
eval -draft %[ ## select the previous line
## select the previous line exec k <a-x>
exec k <a-x> ## if the previous line isn't within a comment scope, break
exec <a-k>^(\h*/\*|\h+\*[^/])<ret>
## simple test to check that the previous comment has been left open
exec <a-K>\*/\h*$<ret>
try %{ try %[
## if the previous line isn't within a comment scope, break ## if the next line is a comment line, add a star
exec <a-k>^(\h*/\*|\h+\*[^/])<ret> exec -draft 2j<a-x><a-k>^\h+\*<ret>
## simple test to check that the previous comment has been left open exec -draft j<a-x>s^\h*<ret>a*<space><esc>
exec <a-K>\*/\h*$<ret> ] catch %[
try %[
try %[ ## if the previous line is an empty comment line, close the comment scope
## if the next line is a comment line, add a star exec -draft <a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
exec -draft 2j<a-x><a-k>^\h+\*<ret> ] catch %[
exec -draft j<a-x>s^\h*<ret>a*<space><esc> ## if the previous line is a non-empty comment line, add a star
] catch %[ exec -draft j<a-x>s^\h*<ret>a*<space><esc>
try %[ ]
## if the previous line is an empty comment line, close the comment scope
exec -draft <a-k>^\h+\*\h+$<ret> <a-x>1s\*(\h*)<ret>c/<esc>
] catch %[
## if the previous line is a non-empty comment line, add a star
exec -draft j<a-x>s^\h*<ret>a*<space><esc>
]
]
## trim trailing whitespace on the previous line
try %[ exec -draft 1s(\h+)$<ret>d ]
## align the new star with the previous one
exec J<a-x>1s^[^*]*(\*)<ret>&
}
] ]
## trim trailing whitespace on the previous line
try %[ exec -draft 1s(\h+)$<ret>d ]
## align the new star with the previous one
exec J<a-x>1s^[^*]*(\*)<ret>&
] ]
] ] ]
# Regions definition are the same between c++ and objective-c # Regions definition are the same between c++ and objective-c
%sh{ %sh{