From 967a55d09f9b33ccc8f213bbf386ed90d001c1e6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 5 Aug 2016 09:37:25 +0100 Subject: [PATCH] c-indent: Tweak implementation of c-family-insert-on-newline --- rc/core/c-family.kak | 55 ++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index b9765d86..c5859c3a 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -76,7 +76,7 @@ def -hidden _c-family-insert-on-closing-curly-brace %[ try %[ exec -itersel -draft hmB^\h*(class|struct|union) a\; ] ] -def -hidden _c-family-insert-on-newline %[ +def -hidden _c-family-insert-on-newline %[ eval -draft %[ exec \; try %[ eval -draft %[ @@ -92,38 +92,33 @@ def -hidden _c-family-insert-on-newline %[ ] ] try %[ - eval -draft %[ - ## select the previous line - exec k + ## select the previous line + exec k + ## if the previous line isn't within a comment scope, break + exec ^(\h*/\*|\h+\*[^/]) + ## simple test to check that the previous comment has been left open + exec \*/\h*$ - try %{ - ## if the previous line isn't within a comment scope, break - exec ^(\h*/\*|\h+\*[^/]) - ## simple test to check that the previous comment has been left open - exec \*/\h*$ - - try %[ - ## if the next line is a comment line, add a star - exec -draft 2j^\h+\* - exec -draft js^\h*a* - ] catch %[ - try %[ - ## if the previous line is an empty comment line, close the comment scope - exec -draft ^\h+\*\h+$ 1s\*(\h*)c/ - ] catch %[ - ## if the previous line is a non-empty comment line, add a star - exec -draft js^\h*a* - ] - ] - - ## trim trailing whitespace on the previous line - try %[ exec -draft 1s(\h+)$d ] - ## align the new star with the previous one - exec J1s^[^*]*(\*)& - } + try %[ + ## if the next line is a comment line, add a star + exec -draft 2j^\h+\* + exec -draft js^\h*a* + ] catch %[ + try %[ + ## if the previous line is an empty comment line, close the comment scope + exec -draft ^\h+\*\h+$ 1s\*(\h*)c/ + ] catch %[ + ## if the previous line is a non-empty comment line, add a star + exec -draft js^\h*a* + ] ] + + ## trim trailing whitespace on the previous line + try %[ exec -draft 1s(\h+)$d ] + ## align the new star with the previous one + exec J1s^[^*]*(\*)& ] -] +] ] # Regions definition are the same between c++ and objective-c %sh{