rework cpp indenter, try to make them more readable
This commit is contained in:
parent
d880465f38
commit
df57870470
|
@ -9,7 +9,7 @@ hook global BufSetOption mimetype=text/x-c(\+\+)? %{
|
|||
def -hidden _cpp_indent_on_new_line %~
|
||||
eval -draft -itersel %_
|
||||
# preserve previous line indent
|
||||
try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P }
|
||||
try %{ exec -draft <space>K<a-&> }
|
||||
# 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
|
||||
|
@ -21,10 +21,15 @@ def -hidden _cpp_indent_on_new_line %~
|
|||
# indent after visibility specifier
|
||||
try %[ exec -draft k<a-x> <a-k> ^\h*(public|private|protected):\h*$ <ret> j<a-gt> ]
|
||||
# indent after if|else|while|for
|
||||
try %[ exec -draft <a-F>)MB<a-k>\`(if|else|while|for)\h*\(.*\)\n\h*\n\'<ret><a-space><space><a-gt> ]
|
||||
try %[ exec -draft <space><a-F>)MB <a-k> \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' <ret> s \`|.\' <ret> 1<a-&>1<a-space><a-gt> ]
|
||||
_
|
||||
~
|
||||
|
||||
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<a-F>)M <a-k> \`\(.*\)\h*\n\h*\{ <ret> s \`|.\' <ret> 1<a-&> ]
|
||||
]
|
||||
|
||||
def -hidden _cpp_indent_on_closing_curly_brace %[
|
||||
# deindent on insert } alone on a line
|
||||
try %[ exec -draft <a-h><a-k> ^\h+\}$ <ret> < ]
|
||||
|
@ -46,6 +51,7 @@ hook global WinSetOption filetype=cpp %[
|
|||
hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>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
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user