diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 3d725ec0..829a56e6 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -36,28 +36,28 @@ hook global BufSetOption mimetype=text/x-objc %{ } def -hidden _c-family-trim-autoindent %[ eval -draft -itersel %[ - ## remove the line if it's empty when leaving the insert mode + # remove the line if it's empty when leaving the insert mode try %[ exec 1s^(\h+)$ d ] ] ] def -hidden _c-family-indent-on-newline %[ eval -draft -itersel %[ exec \; try %[ - ## if previous line closed a paren, copy indent of the opening paren line + # if previous line closed a paren, copy indent of the opening paren line exec -draft k 1s(\))(\h+\w+)*\h*(\;\h*)?$ mJ s\`|.\' 1 ] 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 exec -draft K ] - ## remove previous empty lines resulting from the automatic indent + # remove previous empty lines resulting from the automatic indent try %[ exec -draft k H ^\h+$ d ] - ## indent after an opening brace + # indent after an opening brace try %[ exec -draft K s\{\h*$ j ] - ## indent after a label + # indent after a label try %[ exec -draft k s[a-zA-Z0-9_-]+:\h*$ j ] - ## indent after a statement not followed by an opening brace + # indent after a statement not followed by an opening brace try %[ exec -draft k \b(if|else|for|while)\h*\(.+?\)\h*$ j ] - ## align to the opening parenthesis on a previous line if its followed by text on the same line + # align to the opening parenthesis on a previous line if its followed by text on the same line try %[ exec -draft {b \`\([^\n]+\n[^\n]*\n?\' L s\`|.\' & ] ] ] @@ -80,42 +80,47 @@ def -hidden _c-family-insert-on-newline %[ eval -draft %[ exec \; try %[ eval -draft %[ - ## copy the commenting prefix + # copy the commenting prefix exec -save-regs '' k 1s^\h*(//+\h*) y try %[ - ## if the previous comment isn't empty, create a new one + # if the previous comment isn't empty, create a new one exec ^\h*//+\h*$ js^\h*p ] catch %[ - ## if there is no text in the previous comment, remove it completely + # if there is no text in the previous comment, remove it completely exec d ] ] ] try %[ - ## select the previous line - exec k - ## if the previous line isn't within a comment scope, break - exec ^(\h*/\*|\h+\*[^/]) - ## simple test to check that the previous comment has been left open - exec \*/\h*$ + # if the previous line isn't within a comment scope, break + exec -draft k ^(\h*/\*|\h+\*(?!/)) + + # find comment opening, validate it was not closed, and check its using star prefixes + exec -draft /\* \*/ \`\h*/\*([^\n]*\n\h*\*)*[^\n]*\n\h*.\' try %[ - ## if the next line is a comment line, add a star - exec -draft 2j^\h+\* - exec -draft js^\h*a* + # if the previous line is opening the comment, insert star preceeded by space + exec -draft k^\h*/\* + exec -draft i* ] catch %[ - try %[ - ## if the previous line is an empty comment line, close the comment scope - exec -draft ^\h+\*\h+$ 1s\*(\h*)c/ + try %[ + # if the next line is a comment line insert a star + exec -draft j^\h+\* + exec -draft i* ] catch %[ - ## if the previous line is a non-empty comment line, add a star - exec -draft js^\h*a* + try %[ + # if the previous line is an empty comment line, close the comment scope + exec -draft k^\h+\*\h+$ 1s\*(\h*)c/ + ] catch %[ + # if the previous line is a non-empty comment line, add a star + exec -draft i* + ] ] ] - ## trim trailing whitespace on the previous line + # trim trailing whitespace on the previous line try %[ exec -draft 1s(\h+)$d ] - ## align the new star with the previous one + # align the new star with the previous one exec J1s^[^*]*(\*)& ] ] ] diff --git a/test/regression/918-wrong-asterisk-inserted/cmd b/test/regression/918-wrong-asterisk-inserted/cmd new file mode 100644 index 00000000..966be193 --- /dev/null +++ b/test/regression/918-wrong-asterisk-inserted/cmd @@ -0,0 +1 @@ +A diff --git a/test/regression/918-wrong-asterisk-inserted/in b/test/regression/918-wrong-asterisk-inserted/in new file mode 100644 index 00000000..a18a74c8 --- /dev/null +++ b/test/regression/918-wrong-asterisk-inserted/in @@ -0,0 +1,2 @@ +void foo(int + *ba%(r) diff --git a/test/regression/918-wrong-asterisk-inserted/out b/test/regression/918-wrong-asterisk-inserted/out new file mode 100644 index 00000000..4104039a --- /dev/null +++ b/test/regression/918-wrong-asterisk-inserted/out @@ -0,0 +1,3 @@ +void foo(int + *bar + diff --git a/test/regression/918-wrong-asterisk-inserted/rc b/test/regression/918-wrong-asterisk-inserted/rc new file mode 100644 index 00000000..53c40654 --- /dev/null +++ b/test/regression/918-wrong-asterisk-inserted/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/core/c-family.kak" +set buffer filetype cpp