diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-08-05 09:37:25 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-08-05 09:37:25 +0100 |
| commit | 967a55d09f9b33ccc8f213bbf386ed90d001c1e6 (patch) | |
| tree | 7a5cae27868b9129eebe06e50acbd694aaa8529a | |
| parent | 19e36425f4887156d5370ce5d7e03b75f5471e5d (diff) | |
c-indent: Tweak implementation of c-family-insert-on-newline
| -rw-r--r-- | rc/core/c-family.kak | 57 |
1 files changed, 26 insertions, 31 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 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 \; try %[ eval -draft %[ @@ -92,38 +92,33 @@ def -hidden _c-family-insert-on-newline %[ ] ] try %[ - eval -draft %[ - ## select the previous line - exec k <a-x> - - try %{ - ## 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 %[ - ## if the next line is a comment line, add a star - exec -draft 2j<a-x><a-k>^\h+\*<ret> - exec -draft j<a-x>s^\h*<ret>a*<space><esc> - ] catch %[ - 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>& - } + ## select the previous line + 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 %[ + ## if the next line is a comment line, add a star + exec -draft 2j<a-x><a-k>^\h+\*<ret> + exec -draft j<a-x>s^\h*<ret>a*<space><esc> + ] catch %[ + 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>& ] -] +] ] # Regions definition are the same between c++ and objective-c %sh{ |
