[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kate] /: improve same-line-comments intentation. few more tests added
From: Alex Turbov <i.zaufi () gmail ! com>
Date: 2013-03-15 4:23:20
Message-ID: 20130315042320.89B4CA604F () git ! kde ! org
[Download RAW message or body]
Git commit f77ae73f8458d4c1e2289dca7797d176666348df by Alex Turbov.
Committed on 15/03/2013 at 05:22.
Pushed by turbov into branch 'master'.
improve same-line-comments intentation. few more tests added
M +39 -14 part/script/data/indentation/cppstyle.js
M +2 -1 testdata/indent/cppstyle/.kateconfig
A +1 -0 testdata/indent/cppstyle/comment1/expected
A +4 -0 testdata/indent/cppstyle/comment1/input.js
A +1 -0 testdata/indent/cppstyle/comment1/origin
A +1 -0 testdata/indent/cppstyle/comment2/expected
A +5 -0 testdata/indent/cppstyle/comment2/input.js
A +1 -0 testdata/indent/cppstyle/comment2/origin
A +2 -0 testdata/indent/cppstyle/comment3/expected
A +3 -0 testdata/indent/cppstyle/comment3/input.js
A +1 -0 testdata/indent/cppstyle/comment3/origin
A +3 -0 testdata/indent/cppstyle/doxygen2/expected
A +3 -0 testdata/indent/cppstyle/doxygen2/input.js
A +1 -0 testdata/indent/cppstyle/doxygen2/origin
A +4 -0 testdata/indent/cppstyle/doxygen3/expected
A +3 -0 testdata/indent/cppstyle/doxygen3/input.js
A +3 -0 testdata/indent/cppstyle/doxygen3/origin
http://commits.kde.org/kate/f77ae73f8458d4c1e2289dca7797d176666348df
diff --git a/part/script/data/indentation/cppstyle.js \
b/part/script/data/indentation/cppstyle.js index 4941c5b..68866db 100644
--- a/part/script/data/indentation/cppstyle.js
+++ b/part/script/data/indentation/cppstyle.js
@@ -2,7 +2,7 @@
* name: C++/boost Style
* license: LGPL
* author: Alex Turbov <i.zaufi@gmail.com>
- * revision: 2
+ * revision: 3
* kate-version: 3.4
* priority: 10
* indent-languages: C++11, C++11/Qt4
@@ -36,7 +36,6 @@
* space-indent true;
* auto-brackets true;
* replace-tabs true;
- * replace-tabs true;
* replace-tabs-save true;
*
* \todo Better to check (assert) some of that modelines...
@@ -176,22 +175,48 @@ function alignInlineComment(line)
*/
function tryToKeepInlineComment(line)
{
+ // Make sure that there is some text still present on a prev line
+ // i.e. it was jsut splitted and same-line-comment must be moved back to it
+ if (document.line(line - 1).trim().length == 0)
+ return;
+
// Check is there any comment on the current line
var currentLineText = document.line(line);
var sc = splitByComment(currentLineText);
- if (sc.hasComment && isNotStringOrComment(line, sc.before.length - 1) && \
sc.before.length > 0) + if (sc.hasComment && isNotStringOrComment(line, \
sc.before.length - 1) && sc.after.length > 0) {
- // Yep, try to move it on a previous line.
- // NOTE The latter can't have a comment!
- var lastPos = document.lastColumn(line - 1);
- document.insertText(
- line - 1
- , lastPos + 1
- , String().fill(' ', gSameLineCommentStartAt - lastPos - 1)
- + "//"
- + sc.after.rtrim()
- );
- document.removeText(line, sc.before.rtrim().length, line, \
currentLineText.length); + // Ok, here is few cases possible when ENTER \
pressed in different positions + // | |smth|was here; | |// comment
+ //
+ // If sc.before has some text, it means that cursor was in the middle of \
some + // non-commented text, and part of it left on a prev line, so we have \
to move + // the comment back to that line...
+ if (sc.before.trim().length > 0) // Is there some text \
before comment? + {
+ var lastPos = document.lastColumn(line - 1); // Get last position of \
non space char @ prev line + // Put the comment text to the prev line w/ \
padding + document.insertText(
+ line - 1
+ , lastPos + 1
+ , String().fill(' ', gSameLineCommentStartAt - lastPos - 1)
+ + "//"
+ + sc.after.rtrim()
+ );
+ // Remove it from current line starting from current position
+ // 'till the line end
+ document.removeText(line, sc.before.rtrim().length, line, \
currentLineText.length); + }
+ else
+ {
+ // No text before comment. Need to remove possible spaces from prev \
line... + var prevLine = line - 1;
+ document.removeText(
+ prevLine
+ , document.lastColumn(prevLine) + 1
+ , prevLine
+ , document.lineLength(prevLine)
+ );
+ }
}
}
diff --git a/testdata/indent/cppstyle/.kateconfig \
b/testdata/indent/cppstyle/.kateconfig index b4a842f..5b9afad 100644
--- a/testdata/indent/cppstyle/.kateconfig
+++ b/testdata/indent/cppstyle/.kateconfig
@@ -1 +1,2 @@
-kate: indent-mode cppstyle; replace-tabs true; indent-width 2; dynamic-word-wrap off
+kate: indent-mode cppstyle; replace-tabs true; indent-width 4; dynamic-word-wrap \
off; hl C++11; +
diff --git a/testdata/indent/cppstyle/comment1/expected \
b/testdata/indent/cppstyle/comment1/expected new file mode 100644
index 0000000..7c7e833
--- /dev/null
+++ b/testdata/indent/cppstyle/comment1/expected
@@ -0,0 +1 @@
+int smth; // ok
diff --git a/testdata/indent/cppstyle/comment1/input.js \
b/testdata/indent/cppstyle/comment1/input.js new file mode 100644
index 0000000..a19e564
--- /dev/null
+++ b/testdata/indent/cppstyle/comment1/input.js
@@ -0,0 +1,4 @@
+v.setCursorPosition(0,9);
+v.type("/");
+v.type("/");
+v.type(" ok");
diff --git a/testdata/indent/cppstyle/comment1/origin \
b/testdata/indent/cppstyle/comment1/origin new file mode 100644
index 0000000..9fb9d0d
--- /dev/null
+++ b/testdata/indent/cppstyle/comment1/origin
@@ -0,0 +1 @@
+int smth;
diff --git a/testdata/indent/cppstyle/comment2/expected \
b/testdata/indent/cppstyle/comment2/expected new file mode 100644
index 0000000..399358c
--- /dev/null
+++ b/testdata/indent/cppstyle/comment2/expected
@@ -0,0 +1 @@
+int smth; ///< ok
\ No newline at end of file
diff --git a/testdata/indent/cppstyle/comment2/input.js \
b/testdata/indent/cppstyle/comment2/input.js new file mode 100644
index 0000000..179bdde
--- /dev/null
+++ b/testdata/indent/cppstyle/comment2/input.js
@@ -0,0 +1,5 @@
+v.setCursorPosition(0,9);
+v.type("/");
+v.type("/");
+v.type("/");
+v.type("ok");
diff --git a/testdata/indent/cppstyle/comment2/origin \
b/testdata/indent/cppstyle/comment2/origin new file mode 100644
index 0000000..19ff7bf
--- /dev/null
+++ b/testdata/indent/cppstyle/comment2/origin
@@ -0,0 +1 @@
+int smth;
\ No newline at end of file
diff --git a/testdata/indent/cppstyle/comment3/expected \
b/testdata/indent/cppstyle/comment3/expected new file mode 100644
index 0000000..2e3535a
--- /dev/null
+++ b/testdata/indent/cppstyle/comment3/expected
@@ -0,0 +1,2 @@
+
+ ok// comment
\ No newline at end of file
diff --git a/testdata/indent/cppstyle/comment3/input.js \
b/testdata/indent/cppstyle/comment3/input.js new file mode 100644
index 0000000..cf63129
--- /dev/null
+++ b/testdata/indent/cppstyle/comment3/input.js
@@ -0,0 +1,3 @@
+v.setCursorPosition(0,4);
+v.enter();
+v.type("ok");
diff --git a/testdata/indent/cppstyle/comment3/origin \
b/testdata/indent/cppstyle/comment3/origin new file mode 100644
index 0000000..2ff1ec6
--- /dev/null
+++ b/testdata/indent/cppstyle/comment3/origin
@@ -0,0 +1 @@
+ // comment
\ No newline at end of file
diff --git a/testdata/indent/cppstyle/doxygen2/expected \
b/testdata/indent/cppstyle/doxygen2/expected new file mode 100644
index 0000000..e93fe49
--- /dev/null
+++ b/testdata/indent/cppstyle/doxygen2/expected
@@ -0,0 +1,3 @@
+ /**
+ * ok
+ */
diff --git a/testdata/indent/cppstyle/doxygen2/input.js \
b/testdata/indent/cppstyle/doxygen2/input.js new file mode 100644
index 0000000..1c1c1d5
--- /dev/null
+++ b/testdata/indent/cppstyle/doxygen2/input.js
@@ -0,0 +1,3 @@
+v.setCursorPosition(0,7);
+v.enter();
+v.type("ok");
diff --git a/testdata/indent/cppstyle/doxygen2/origin \
b/testdata/indent/cppstyle/doxygen2/origin new file mode 100644
index 0000000..c100536
--- /dev/null
+++ b/testdata/indent/cppstyle/doxygen2/origin
@@ -0,0 +1 @@
+ /**
\ No newline at end of file
diff --git a/testdata/indent/cppstyle/doxygen3/expected \
b/testdata/indent/cppstyle/doxygen3/expected new file mode 100644
index 0000000..0b4db0d
--- /dev/null
+++ b/testdata/indent/cppstyle/doxygen3/expected
@@ -0,0 +1,4 @@
+/**
+ *
+ * ok
+ */
diff --git a/testdata/indent/cppstyle/doxygen3/input.js \
b/testdata/indent/cppstyle/doxygen3/input.js new file mode 100644
index 0000000..e844fe4
--- /dev/null
+++ b/testdata/indent/cppstyle/doxygen3/input.js
@@ -0,0 +1,3 @@
+v.setCursorPosition(1,3);
+v.enter();
+v.type("ok");
diff --git a/testdata/indent/cppstyle/doxygen3/origin \
b/testdata/indent/cppstyle/doxygen3/origin new file mode 100644
index 0000000..e89970a
--- /dev/null
+++ b/testdata/indent/cppstyle/doxygen3/origin
@@ -0,0 +1,3 @@
+/**
+ *
+ */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic