diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index 6e957f01..e0c35967 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -18,18 +18,28 @@ hook global WinSetOption filetype=cpp %~ addhl -group cpp-highlight regex "^\h*?#.*?(?s\h+$d } } # cleanup trailing whitespaces when exiting insert mode + + # cleanup trailing whitespaces when exiting insert mode + hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft s\h+$d } } hook window InsertChar \n -id cpp-indent %@ eval -draft -itersel %_ - try %{ exec -draft ks^\h+yjP } # preserve previous line indent - try %[ exec -draft k[{(]\h*$j ] # indent after lines ending with { or ( - try %{ exec -draft ks\h+$d } # cleanup trailing white space son previous line - try %{ exec -draft [(\`\([^\n]+\n[^\n]*\n?\'s\`..|.\'& } # align to opening paren of previous line - try %{ exec -draft ks^\h*\K(/{2,})yP } # copy // comments prefix + # preserve previous line indent + try %{ exec -draft ks^\h+yjP } + # indent after lines ending with { or ( + try %[ exec -draft k[{(]\h*$j ] + # cleanup trailing white space son previous line + try %{ exec -draft ks\h+$d } + # align to opening paren of previous line + try %{ exec -draft [(\`\([^\n]+\n[^\n]*\n?\'s\`..|.\'& } + # copy // comments prefix + try %{ exec -draft ks^\h*\K(/{2,})yP } _ @ + hook window InsertChar \} -id cpp-indent %[ - try %[ exec -draft ^\h+\}$< ] # deindent on insert } alone on a line - try %[ exec -draft "hm(class|struct)\`(class|struct)[^{}\n]+(\n)?\s*\{\'ma;" ] # add ; after } if class or struct definition + # deindent on insert } alone on a line + try %[ exec -draft ^\h+\}$< ] + # add ; after } if class or struct definition + try %[ exec -draft "hm(class|struct)\`(class|struct)[^{}\n]+(\n)?\s*\{\'ma;" ] ] ~