125
125
return text.rtrim();
128
/// Return \c true if attribute at given position is a \e Comment
129
function isComment(line, column)
131
// Check if we are not withing a string or a comment
132
var c = new Cursor(line, column);
133
var mode = document.attributeName(c);
134
dbg("isComment: Check mode @ " + c + ": " + mode);
135
return gMode == "Doxygen" || document.isComment(c);
138
/// Return \c true if attribute at given position is a \e String
139
function isString(line, column)
141
// Check if we are not withing a string or a comment
142
var c = new Cursor(line, column);
143
var mode = document.attributeName(c);
144
dbg("isString: Check mode @ " + c + ": " + mode);
145
return document.isString(c) || document.isChar(c);
128
148
/// Return \c true if attribute at given position is a \e String or \e Comment
129
149
function isStringOrComment(line, column)
131
// Check if we are not withning a string or a comment
151
// Check if we are not withing a string or a comment
132
152
var c = new Cursor(line, column);
133
153
var mode = document.attributeName(c);
134
154
dbg("isStringOrComment: Check mode @ " + c + ": " + mode);
135
155
return gMode == "Doxygen" || document.isString(c) || document.isChar(c) || document.isComment(c);
158
function tryIndentRelativePrevLine(line)
160
var current_line = line - 1;
161
while (0 <= current_line && isStringOrComment(current_line, document.firstColumn(current_line)))
163
if (current_line == -1)
166
var prevLineFirstChar = document.firstChar(current_line);
167
var needHalfUnindent = !(
168
prevLineFirstChar == ','
169
|| prevLineFirstChar == ':'
170
|| prevLineFirstChar == '?'
171
|| prevLineFirstChar == '<'
172
|| prevLineFirstChar == '>'
173
|| prevLineFirstChar == '&'
175
return document.firstColumn(current_line) - (needHalfUnindent ? 2 : 0);
138
178
/// Try to (re)align (to 60th position) inline comment if present
139
179
function alignInlineComment(line)
141
document.editBegin();
142
181
// Check is there any comment on the current line
143
182
var currentLineText = document.line(line);
144
183
var sc = splitByComment(currentLineText);
1150
1201
var line = cursor.line;
1151
1202
var column = cursor.column;
1152
1203
// Check is comma a very first character on a line...
1153
if (document.firstChar(line) == ',' && document.firstColumn(line) == (column - 1))
1155
var prevLineFirstChar = document.firstChar(line - 1);
1156
var mustMove = !(prevLineFirstChar == ',' || prevLineFirstChar == ':');
1157
result = document.firstColumn(line - 1) - (mustMove ? 2 : 0);
1159
document.editBegin();
1204
if (justEnteredCharIsFirstOnLine(line, column, ','))
1205
result = tryIndentRelativePrevLine(line);
1160
1207
cursor = tryJumpOverParenthesis(cursor); // Try to jump out of parenthesis
1161
1208
if (document.charAt(cursor) != ' ')
1162
1209
document.insertText(cursor, " "); // Add space only if not present
1164
view.setCursorPosition(line, column + 2); // Otherwise just move cursor after it
1211
view.setCursorPosition(line, column + 1); // Otherwise just move cursor after it
1234
1280
if (isStringOrComment(line, column))
1235
1281
return result; // Do nothing for comments and strings
1237
document.editBegin();
1239
1283
// If ';' is a first char on a line?
1240
if (document.firstChar(line) == ';' && document.firstColumn(line) == (column - 1))
1284
if (justEnteredCharIsFirstOnLine(line, column, ';'))
1242
1286
// Check if we are inside a `for' statement
1243
1287
var openBracePos = document.anchor(line, column, '(');
1320
1363
if (isStringOrComment(line, column))
1321
1364
return result; // Do nothing for comments and strings
1323
var isFirstChar = document.firstChar(line) == ch
1324
&& document.firstColumn(line) == (column - 1)
1326
var halfTabNeeded = isFirstChar
1366
var halfTabNeeded = justEnteredCharIsFirstOnLine(line, column, ch)
1327
1367
&& document.line(line - 1).search(/^\s*[A-Za-z_][A-Za-z0-9_]*/) != -1
1329
1369
dbg("tryOperator: halfTabNeeded=",halfTabNeeded);
1773
1801
* the next one (after \c '"') is not an alphanumeric,
1774
1802
* then add a delimiters.
1776
* \attention If autobrace plugin used to add quotation marks,
1777
* then next symbol after the current will be another one \c '"'
1778
* if this is a new string. Otherwise, if it turned OFF, the simplest
1779
* case we can detect (and the most typical), is that raw string started
1780
* at fresh line, and current \c column equal to the line length.
1804
* \attention Effect of AutoBrace extension has already neutralized at this point :)
1782
function tryRawStringLiteral(cursor)
1806
function tryStringLiteral(cursor, ch)
1784
1808
var line = cursor.line;
1785
1809
var column = cursor.column;
1786
var is_abp_on = document.charAt(line, column) == '"';
1787
var start_raw_string = 2 <= column
1788
&& document.charAt(line, column - 2) == 'R'
1790
is_abp_on // Autobracket plugin On?
1791
|| column == (document.lineLength(line)) // Autobracket plugin Off? (and end of line)
1793
if (start_raw_string)
1811
if (isComment(line, column - 2)) // Do nothing for comments
1814
// First of all we have to determinate where we are:
1815
// 0) new string literal just started, or ...
1816
// 1) string literal just ends
1818
// Check if the '"' is a very first char on a line
1819
var new_string_just_started;
1821
// Yes, then we have to look to the last char of the previous line
1822
new_string_just_started = !(line != 0 && isString(line - 1, document.lastColumn(line - 1)));
1824
// Ok, just check attribute of the char right before '"'
1825
new_string_just_started = !isString(line, column - 2);
1828
if (new_string_just_started)
1795
document.editBegin();
1796
/// \todo Make delimiter configurable... HOW?
1797
/// It would be nice if indenters can have a configuration page somehow...
1798
document.insertText(cursor, "~()~");
1800
document.insertText(line, column + 4, '"');
1801
view.setCursorPosition(line, column + 2);
1830
// Is there anything after just entered '"'?
1831
var nc = document.charAt(line, column);
1832
var need_closing_quote = column == document.lineLength(line)
1833
|| document.isSpace(nc)
1834
|| nc == ',' // user tries to add new string param,
1835
|| nc == ')' // ... or one more param to the end of some call
1836
|| nc == ']' // ... or string literal as subscript index
1837
|| nc == ';' // ... or one more string before end of expression
1838
|| nc == '<' // ... or `some << "|<<`
1840
if (need_closing_quote)
1842
// Check for 'R' right before '"'
1843
if (ch == '"' && document.charAt(line, column - 2) == 'R')
1845
// Yeah, looks like a raw string literal
1846
/// \todo Make delimiter configurable... HOW?
1847
/// It would be nice if indenters can have a configuration page somehow...
1848
document.insertText(cursor, "~()~\"");
1849
view.setCursorPosition(line, column + 2);
1853
document.insertText(cursor, ch);
1854
view.setCursorPosition(line, column);
1900
1952
// Make sure there is a space at given position
1901
1953
dbg("addCharOrJumpOverIt: checking @Cursor("+line+","+column+"), c='"+document.charAt(line, column)+"'");
1902
if (column < document.lineLength(line) || document.charAt(line, column) != char)
1954
if (document.lineLength(line) <= column || document.charAt(line, column) != char)
1903
1955
document.insertText(line, column, char);
1904
1956
view.setCursorPosition(line, column + 1);