summaryrefslogtreecommitdiff
path: root/src/rc/cpp.kak
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-11-07 21:58:19 +0000
committerMaxime Coste <frrrwww@gmail.com>2013-11-07 21:58:19 +0000
commit82b1619b058d47f5643307d6d34c28d697c21017 (patch)
tree7346c902b7711c5eb89da0fa5557f9cc9f7358b8 /src/rc/cpp.kak
parenta11bccaa1269636281605814c095bae543905278 (diff)
cleanup cpp hooks
Diffstat (limited to 'src/rc/cpp.kak')
-rw-r--r--src/rc/cpp.kak26
1 files changed, 18 insertions, 8 deletions
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*?#.*?(?<!\\)$" 0:macro
addhl -group cpp-highlight regex "(?<!')\".*?(?<!\\)(\\\\)*\"" 0:string
addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" 0:comment
- hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } } # cleanup trailing whitespaces when exiting insert mode
+
+ # cleanup trailing whitespaces when exiting insert mode
+ hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } }
hook window InsertChar \n -id cpp-indent %@ eval -draft -itersel %_
- try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P } # preserve previous line indent
- try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ] # indent after lines ending with { or (
- try %{ exec -draft k<a-x>s\h+$<ret>d } # cleanup trailing white space son previous line
- try %{ exec -draft [(<a-k>\`\([^\n]+\n[^\n]*\n?\'<ret>s\`..|.\'<ret>& } # align to opening paren of previous line
- try %{ exec -draft <c-s>k<a-x>s^\h*\K(/{2,})<ret>y<c-o>P } # copy // comments prefix
+ # preserve previous line indent
+ try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P }
+ # indent after lines ending with { or (
+ try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ]
+ # cleanup trailing white space son previous line
+ try %{ exec -draft k<a-x>s\h+$<ret>d }
+ # align to opening paren of previous line
+ try %{ exec -draft [(<a-k>\`\([^\n]+\n[^\n]*\n?\'<ret>s\`..|.\'<ret>& }
+ # copy // comments prefix
+ try %{ exec -draft <c-s>k<a-x>s^\h*\K(/{2,})<ret>y<c-o>P }
_ @
+
hook window InsertChar \} -id cpp-indent %[
- try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ] # deindent on insert } alone on a line
- try %[ exec -draft "hm<space><a-?>(class|struct)<ret><a-k>\`(class|struct)[^{}\n]+(\n)?\s*\{\'<ret><a-space>ma;<esc>" ] # add ; after } if class or struct definition
+ # deindent on insert } alone on a line
+ try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ]
+ # add ; after } if class or struct definition
+ try %[ exec -draft "hm<space><a-?>(class|struct)<ret><a-k>\`(class|struct)[^{}\n]+(\n)?\s*\{\'<ret><a-space>ma;<esc>" ]
]
~