From f2eb2e8b1cbbe71bf60f99bb576490cda164a783 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 10 Oct 2015 16:25:46 +0300 Subject: [PATCH 1/2] Add support for astyle code-formatting --- rc/c-family.kak | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/rc/c-family.kak b/rc/c-family.kak index 58ae6815c..6486ab42b 100644 --- a/rc/c-family.kak +++ b/rc/c-family.kak @@ -68,6 +68,17 @@ def -hidden _c-family-indent-on-closing-curly-brace %[ try %[ exec -draft "hm;(class|struct|union)\`(class|struct|union)[^{}\n]+(\n)?\s*\{\'ma;" ] ] +decl str c_astyle_options "" +def c-format-astyle -docstring "Format C/C++/Obj-C code using the astyle utility" %{ + %sh{ + readonly x=$((kak_cursor_column - 1)) + readonly y="${kak_cursor_line}" + + echo "exec -draft %{%|astyle${kak_opt_c_astyle_options// /}}" + echo "exec gg ${y}g ${x}l" + } +} + # Regions definition are the same between c++ and objective-c %sh{ for ft in c cpp objc; do @@ -122,13 +133,18 @@ hook global WinSetOption filetype=(c|cpp|objc) %[ alias window alt c-family-alternative-file alias window comment-selection c-family-comment-selection + + alias window format-code c-format-astyle ] hook global WinSetOption filetype=(?!(c|cpp|objc)$).* %[ - rmhooks window c-family-indent rmhooks window c-family-hooks + rmhooks window c-family-indent + unalias window alt c-family-alternative-file unalias window comment-selection c-family-comment-selection + + unalias window format-code ] hook global WinSetOption filetype=c %[ addhl ref c ] From 1713f14d5c79e483222755c0f7682024f94bc620 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 21 Oct 2015 07:50:11 +0300 Subject: [PATCH 2/2] Add an alias for commenting whole lines, fix the call to unalias --- rc/c-family.kak | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rc/c-family.kak b/rc/c-family.kak index 6486ab42b..cbaf30723 100644 --- a/rc/c-family.kak +++ b/rc/c-family.kak @@ -133,6 +133,7 @@ hook global WinSetOption filetype=(c|cpp|objc) %[ alias window alt c-family-alternative-file alias window comment-selection c-family-comment-selection + alias window comment-line c-family-comment-line alias window format-code c-format-astyle ] @@ -143,8 +144,9 @@ hook global WinSetOption filetype=(?!(c|cpp|objc)$).* %[ unalias window alt c-family-alternative-file unalias window comment-selection c-family-comment-selection + unalias window comment-line c-family-comment-line - unalias window format-code + unalias window format-code c-format-astyle ] hook global WinSetOption filetype=c %[ addhl ref c ]