Git commit 718f9f65a82e935760b5ccd6e9a16cd575ff4663 by Alex Turbov. Committed on 30/11/2013 at 21:47. Pushed by turbov into branch 'master'. improve c++ indenter behaviour after string/char literals and operators aft= er them M +25 -25 part/script/data/indentation/cppstyle.js http://commits.kde.org/kate/718f9f65a82e935760b5ccd6e9a16cd575ff4663 diff --git a/part/script/data/indentation/cppstyle.js b/part/script/data/in= dentation/cppstyle.js index a06cf29..e5135a1 100644 --- a/part/script/data/indentation/cppstyle.js +++ b/part/script/data/indentation/cppstyle.js @@ -135,6 +135,19 @@ function isStringOrComment(line, column) return gMode =3D=3D "Doxygen" || document.isString(c) || document.isCh= ar(c) || document.isComment(c); } = +/** + * Add a character \c c to the given position if absent. + * Set new cursor position to the next one after the current. + */ +function addCharOrJumpOverIt(line, column, char) +{ + // Make sure there is a space at given position + dbg("addCharOrJumpOverIt: checking @Cursor("+line+","+column+"), c=3D'= "+document.charAt(line, column)+"'"); + if (document.lineLength(line) <=3D column || document.charAt(line, col= umn) !=3D char) + document.insertText(line, column, char); + view.setCursorPosition(line, column + 1); +} + function tryIndentRelativePrevLine(line) { var current_line =3D line - 1; @@ -1030,7 +1043,7 @@ function tryTemplate(cursor) else { cursor =3D tryJumpOverParenthesis(cursor); // Try to ju= mp out of parenthesis - tryAddSpaceAfterClosedBracket(cursor); + tryAddSpaceAfterClosedBracketOrQuote(cursor); } document.editEnd(); return result; @@ -1079,7 +1092,7 @@ function tryJumpOverParenthesis(cursor) // Check that we r inside of parenthesis and some symbol between var pc =3D document.charAt(line, column - 2); var cc =3D document.charAt(cursor); - if (column > 2 && pc =3D=3D '(' && cc =3D=3D ')') + if ((pc =3D=3D '(' && cc =3D=3D ')') || (pc =3D=3D '{' && cc =3D=3D '}= ')) { var c =3D document.charAt(line, column - 1); switch (c) @@ -1096,6 +1109,7 @@ function tryJumpOverParenthesis(cursor) case '<': case '>': case '}': + case ')': case ']': // NOTE '[' co= uld be a part of lambda { // Ok, move character out of parenthesis @@ -1117,14 +1131,14 @@ function tryJumpOverParenthesis(cursor) * \li \c ) -- ordinal function call * \li \c } -- C++11 constructor call * \li \c ] -- array access + * \li \c " -- end of a string literal + * \li \c ' -- and of a char literal * - * This function try to add a space between a closing bracket and operator= char. + * This function try to add a space between a closing quote/bracket and op= erator char. * * \note This valid if we r not inside a comment or a string literal. - * - * \attention This function \b never calls \c editEnd() for a given \c es = instance! */ -function tryAddSpaceAfterClosedBracket(cursor) +function tryAddSpaceAfterClosedBracketOrQuote(cursor) { var line =3D cursor.line; var column =3D cursor.column; @@ -1134,12 +1148,12 @@ function tryAddSpaceAfterClosedBracket(cursor) = // Check if we have a closing bracket before a last entered char var b =3D document.charAt(line, column - 2); - dbg("tryAddSpaceAfterClosedBracket: b=3D'"+b+"', @"+new Cursor(line, c= olumn -2)); - if (!(b =3D=3D ']' || b =3D=3D '}' || b =3D=3D ')')) + if (!(b =3D=3D ']' || b =3D=3D '}' || b =3D=3D ')' || b =3D=3D '"' || = b =3D=3D "'")) return cursor; = // Ok, lets check what we've got as a last char var c =3D document.charAt(line, column - 1); + dbg("tryAddSpaceAfterClosedBracketOrQuote: c=3D'"+c+"', @"+new Cursor(= line, column-1)); switch (c) { case '*': @@ -1152,7 +1166,6 @@ function tryAddSpaceAfterClosedBracket(cursor) case '?': case ':': case '<': - dbg("tryAddSpaceAfterClosedBracket: c=3D'"+c+"', @"+new Cursor= (line, column -1)); document.insertText(line, column - 1, " "); view.setCursorPosition(line, column + 1); return view.cursorPosition(); @@ -1370,7 +1383,7 @@ function tryOperator(cursor, ch) document.editBegin(); var prev =3D cursor; cursor =3D tryJumpOverParenthesis(cursor); // Try to ju= mp out of parenthesis - cursor =3D tryAddSpaceAfterClosedBracket(cursor); + cursor =3D tryAddSpaceAfterClosedBracketOrQuote(cursor); = // Check if a space before '?' still needed if (prev =3D=3D cursor && ch =3D=3D '?' && document.charAt(line, curso= r.column - 1) !=3D ' ') @@ -1670,7 +1683,7 @@ function tryColon(cursor) else { cursor =3D tryJumpOverParenthesis(cursor); // Try to ju= mp out of parenthesis - tryAddSpaceAfterClosedBracket(cursor); // Try add a s= pace after close bracket + tryAddSpaceAfterClosedBracketOrQuote(cursor); // Try add a s= pace after close bracket } } document.editEnd(); @@ -1922,19 +1935,6 @@ function tryKeywordsWithBrackets(cursor) } = /** - * Add a character \c c to the given position if absent. - * Set new cursor position to the next one after the current. - */ -function addCharOrJumpOverIt(line, column, char) -{ - // Make sure there is a space at given position - dbg("addCharOrJumpOverIt: checking @Cursor("+line+","+column+"), c=3D'= "+document.charAt(line, column)+"'"); - if (document.lineLength(line) <=3D column || document.charAt(line, col= umn) !=3D char) - document.insertText(line, column, char); - view.setCursorPosition(line, column + 1); -} - -/** * Try to add space before, after some equal operators. */ function tryEqualOperator(cursor) @@ -2136,7 +2136,7 @@ function processChar(line, ch) break; case '*': case '&': - tryAddSpaceAfterClosedBracket(cursor); + tryAddSpaceAfterClosedBracketOrQuote(cursor); break; default: break; // Nothing to = do...