From df57870470c0249b59f9203c16ddb7b8f3375d8e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 3 Dec 2013 19:43:33 +0000 Subject: [PATCH] rework cpp indenter, try to make them more readable --- src/rc/cpp.kak | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index ed8fcb69..59cbe8c0 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -9,25 +9,30 @@ hook global BufSetOption mimetype=text/x-c(\+\+)? %{ def -hidden _cpp_indent_on_new_line %~ eval -draft -itersel %_ # preserve previous line indent - try %{ exec -draft ks^\h+yjP } + try %{ exec -draft K } # indent after lines ending with { or ( - try %[ exec -draft k[{(]\h*$j ] + try %[ exec -draft k [{(]\h*$ j ] # cleanup trailing white space son previous line - try %{ exec -draft ks\h+$d } + try %{ exec -draft k s \h+$ d } # align to opening paren of previous line - try %{ exec -draft [(\`\([^\n]+\n[^\n]*\n?\'s\`\(\h*.|.\'& } + try %{ exec -draft [( \`\([^\n]+\n[^\n]*\n?\' s \`\(\h*.|.\' & } # copy // comments prefix - try %{ exec -draft ks^\h*\K(/{2,})yP } + try %{ exec -draft k s ^\h*\K(/{2,}) yP } # indent after visibility specifier - try %[ exec -draft k^\h*(public|private|protected):\h*$j ] + try %[ exec -draft k ^\h*(public|private|protected):\h*$ j ] # indent after if|else|while|for - try %[ exec -draft )MB\`(if|else|while|for)\h*\(.*\)\n\h*\n\' ] + try %[ exec -draft )MB \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' s \`|.\' 11 ] _ ~ +def -hidden _cpp_indent_on_opening_curly_brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ exec -draft -itersel h)M \`\(.*\)\h*\n\h*\{ s \`|.\' 1 ] +] + def -hidden _cpp_indent_on_closing_curly_brace %[ # deindent on insert } alone on a line - try %[ exec -draft ^\h+\}$< ] + try %[ exec -draft ^\h+\}$ < ] # add ; after } if class or struct definition try %[ exec -draft "hm(class|struct)\`(class|struct)[^{}\n]+(\n)?\s*\{\'ma;" ] ] @@ -46,6 +51,7 @@ hook global WinSetOption filetype=cpp %[ hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft s\h+$d } } hook window InsertChar \n -id cpp-indent _cpp_indent_on_new_line + hook window InsertChar \{ -id cpp-indent _cpp_indent_on_opening_curly_brace hook window InsertChar \} -id cpp-indent _cpp_indent_on_closing_curly_brace ]