diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 5d57d2ba..962a4b61 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -31,7 +31,10 @@ define-command -hidden c-family-trim-autoindent %{ define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -itersel %< execute-keys \; 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 /\* ^\h*[^/*\h] + > catch %< + # else if previous line closed a paren, copy indent of the opening paren line execute-keys -draft k 1s(\))(\h+\w+)*\h*(\;\h*)?$ mJ 1 > catch %< # 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 hmB\A\h*(class|struct|union|enum) a\; ] ] -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 \; try %[ evaluate-commands -draft %[ @@ -99,7 +102,7 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -draft %[ try %[ # if the previous line is opening the comment, insert star preceeded by space execute-keys -draft k^\h*/\* - execute-keys -draft i* + execute-keys -draft i* ] catch %[ try %[ # 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 - try %[ execute-keys -draft 1s(\h+)$d ] + try %[ execute-keys -draft s\h+$ d ] # align the new star with the previous one - execute-keys J1s^[^*]*(\*)& + execute-keys K1s^[^*]*(\*)& ] ] ] diff --git a/test/indent/c-family/comment-line-continuation/cmd b/test/indent/c-family/comment-line-continuation/cmd new file mode 100644 index 00000000..3c64ef2d --- /dev/null +++ b/test/indent/c-family/comment-line-continuation/cmd @@ -0,0 +1 @@ +cbar diff --git a/test/indent/c-family/comment-line-continuation/in b/test/indent/c-family/comment-line-continuation/in new file mode 100644 index 00000000..43e9bec3 --- /dev/null +++ b/test/indent/c-family/comment-line-continuation/in @@ -0,0 +1,3 @@ +/* foo%( ) + +// foo%( ) diff --git a/test/indent/c-family/comment-line-continuation/out b/test/indent/c-family/comment-line-continuation/out new file mode 100644 index 00000000..73734b7a --- /dev/null +++ b/test/indent/c-family/comment-line-continuation/out @@ -0,0 +1,8 @@ +/* foo + * bar + */ + + +// foo +// bar + diff --git a/test/indent/c-family/comment-line-continuation/rc b/test/indent/c-family/comment-line-continuation/rc new file mode 100644 index 00000000..53c40654 --- /dev/null +++ b/test/indent/c-family/comment-line-continuation/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/core/c-family.kak" +set buffer filetype cpp