1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 17:02:06 +03:00

c-family.kak: Fix comment line continuation behaviour

Fixes #2043
This commit is contained in:
Maxime Coste 2018-05-19 14:10:05 +10:00
parent ec0f8fe574
commit 8c6af54db3
5 changed files with 23 additions and 5 deletions

View File

@ -31,7 +31,10 @@ define-command -hidden c-family-trim-autoindent %{
define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -itersel %< define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -itersel %<
execute-keys \; execute-keys \;
try %< try %<
# if previous line closed a paren, copy indent of the opening paren line # if previous line is part of a comment, do nothing
execute-keys -draft <a-?>/\*<ret> <a-K>^\h*[^/*\h]<ret>
> catch %<
# else if previous line closed a paren, copy indent of the opening paren line
execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?$<ret> m<a-\;>J <a-S> 1<a-&> execute-keys -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?$<ret> m<a-\;>J <a-S> 1<a-&>
> catch %< > catch %<
# else indent new lines with the same level as the previous one # else indent new lines with the same level as the previous one
@ -74,7 +77,7 @@ define-command -hidden c-family-insert-on-closing-curly-brace %[
try %[ execute-keys -itersel -draft hm<a-x>B<a-x><a-k>\A\h*(class|struct|union|enum)<ret> a\;<esc> ] try %[ execute-keys -itersel -draft hm<a-x>B<a-x><a-k>\A\h*(class|struct|union|enum)<ret> a\;<esc> ]
] ]
define-command -hidden c-family-insert-on-newline %[ evaluate-commands -draft %[ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[
execute-keys \; execute-keys \;
try %[ try %[
evaluate-commands -draft %[ evaluate-commands -draft %[
@ -99,7 +102,7 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -draft %[
try %[ try %[
# if the previous line is opening the comment, insert star preceeded by space # if the previous line is opening the comment, insert star preceeded by space
execute-keys -draft k<a-x><a-k>^\h*/\*<ret> execute-keys -draft k<a-x><a-k>^\h*/\*<ret>
execute-keys -draft i<space>*<space><esc> execute-keys -draft i*<space><esc>
] catch %[ ] catch %[
try %[ try %[
# if the next line is a comment line insert a star # if the next line is a comment line insert a star
@ -117,9 +120,9 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -draft %[
] ]
# trim trailing whitespace on the previous line # trim trailing whitespace on the previous line
try %[ execute-keys -draft 1s(\h+)$<ret>d ] try %[ execute-keys -draft s\h+$<ret> d ]
# align the new star with the previous one # align the new star with the previous one
execute-keys J<a-x>1s^[^*]*(\*)<ret>& execute-keys K<a-x>1s^[^*]*(\*)<ret>&
] ]
] ] ] ]

View File

@ -0,0 +1 @@
c<ret>bar<ret><ret><esc>

View File

@ -0,0 +1,3 @@
/* foo%( )
// foo%( )

View File

@ -0,0 +1,8 @@
/* foo
* bar
*/
// foo
// bar

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/core/c-family.kak"
set buffer filetype cpp