[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/kotlin-mode 76921927de 117/162: Add a test for correct ind
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/kotlin-mode 76921927de 117/162: Add a test for correct indentation of sample.kt, and get it to pass (with a few tweaks) |
Date: |
Sat, 29 Jan 2022 08:25:29 -0500 (EST) |
branch: elpa/kotlin-mode
commit 76921927defb863c543faf0862a8444ac9ffe94c
Author: Martin Blake <martinblake@github.com>
Commit: Martin Blake <martinblake@github.com>
Add a test for correct indentation of sample.kt, and get it to pass (with a
few tweaks)
---
kotlin-mode.el | 65 +++++++++++++++++++++++++++------------------
test/kotlin-mode-test.el | 68 ++++++++++++++++++++++++++++++++++--------------
test/sample.kt | 30 +++++++++++----------
3 files changed, 104 insertions(+), 59 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index a5df662fbc..cfa8bfc5d1 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -331,34 +331,43 @@
"Return whether the current line ends with the given pattern"
(looking-at (format ".*%s[ \t]*$" pattern)))
-(defun kotlin-mode--count-brackets ()
- "Count the brackets on the current line, counting
- +1 for open-brackets, -1 for close-brackets"
- (let ((net-count 0))
- (save-excursion
- (while (not (eolp))
- (cond ((looking-at "\\s\(")
- (incf net-count))
- ((looking-at "\\s\)")
- (decf net-count)))
- (forward-char 1)))
- net-count))
+(defun kotlin-mode--update-bracket-count (net-count)
+ "Count the brackets on the current line, incrementing the count
+ +1 for open-brackets, -1 for close-brackets.
+ Return as soon as the overall count exceeds zero."
+ (save-excursion
+ (end-of-line)
+ (while (and (<= net-count 0) (not (bolp)))
+ (backward-char)
+ (cond ((looking-at "\\s\(")
+ (incf net-count))
+ ((looking-at "\\s\)")
+ (decf net-count)))))
+ net-count)
+
+(defun kotlin-mode--base-indentation ()
+ "Return the indentation level of the current line based on brackets only,
+ i.e. ignoring 'continuation' indentation."
+ (if (kotlin-mode--line-begins "\\.")
+ (- (current-indentation) kotlin-tab-width)
+ (current-indentation)))
(defun kotlin-mode--post-bracket-indent ()
"Return the indentation at the first non-whitespace character
following the last un-closed open-bracket on the line.
- If no non-whitespace character follows, return nil."
+ If no non-whitespace character follows, return the default
+ indentation level."
(let ((net-count 0) position)
(save-excursion
(end-of-line)
(while (and (<= net-count 0) (not (bolp)))
+ (backward-char)
(cond ((looking-at "\\s\(")
(incf net-count))
((looking-at "\\s\)")
- (decf net-count)))
- (backward-char))
+ (decf net-count))))
(if (kotlin-mode--line-ends "\\s\(")
- nil
+ (+ (kotlin-mode--base-indentation) kotlin-tab-width)
(forward-char)
(skip-syntax-forward "(")
(skip-syntax-forward "-")
@@ -378,31 +387,35 @@
(kotlin-mode--beginning-of-buffer-indent))
(let ((not-indented t) cur-indent (net-bracket-count 0))
;; Count any close-bracket at the start of the current line
- (if (kotlin-mode--line-begins "\\s\)")
- (decf net-bracket-count))
+ (save-excursion
+ (skip-syntax-forward "-")
+ (decf net-bracket-count (skip-syntax-forward ")")))
(save-excursion
(while not-indented
;; Count-up the brackets in the previous line
(kotlin-mode--prev-line)
- (incf net-bracket-count (kotlin-mode--count-brackets))
+ (setq net-bracket-count
+ (kotlin-mode--update-bracket-count net-bracket-count))
(cond
;; If the net-bracket-count is zero, use this indentation
((= net-bracket-count 0)
- (setq cur-indent (current-indentation))
+ (setq cur-indent (kotlin-mode--base-indentation))
(setq not-indented nil))
;; If we've now counted more open-brackets than close-brackets,
- ;; use the indentation of the content immediately following the
final open-bracket.
- ;; But if the line *ends* with an open-bracket, apply the default
indentation.
+ ;; use the indentation of the content immediately following the
+ ;; final open-bracket.
+ ;; But if the line *ends* with an open-bracket, apply the default
+ ;; indentation.
((> net-bracket-count 0)
- (let ((post-bracket-indent (kotlin-mode--post-bracket-indent)))
- (if post-bracket-indent
- (setq cur-indent post-bracket-indent)
- (setq cur-indent (+ (current-indentation) kotlin-tab-width))))
+ (setq cur-indent (kotlin-mode--post-bracket-indent))
(setq not-indented nil))
((bobp)
(setq not-indented nil)))))
+ ;; Add extra indentation if the line starts with a period
+ (if (kotlin-mode--line-begins "\\.")
+ (incf cur-indent kotlin-tab-width))
(if cur-indent
(indent-line-to cur-indent)
diff --git a/test/kotlin-mode-test.el b/test/kotlin-mode-test.el
index 3504bc19e5..8cbabe3316 100644
--- a/test/kotlin-mode-test.el
+++ b/test/kotlin-mode-test.el
@@ -47,28 +47,58 @@ return a + b
return a + b
}")))))
-;; (ert-deftest kotlin-mode--chained-methods ()
-;; (with-temp-buffer
-;; (let ((text "names.filter { it.empty }
-;; .sortedBy { it }
-;; .map { it.toUpperCase() }
-;; .forEach { print(it) }"))
+(ert-deftest kotlin-mode--chained-methods ()
+ (with-temp-buffer
+ (let ((text "names.filter { it.empty }
+.sortedBy { it }
+.map { it.toUpperCase() }
+.forEach { print(it) }"))
+
+ (insert text)
+ (beginning-of-buffer)
+
+ (kotlin-mode--indent-line)
+
+ (next-line)
+ (kotlin-mode--indent-line)
-;; (insert text)
-;; (beginning-of-buffer)
+ (next-line)
+ (kotlin-mode--indent-line)
+
+ (next-line)
+ (kotlin-mode--indent-line)
-;; (kotlin-mode--indent-line)
+ (should (equal (buffer-string) "names.filter { it.empty }
+ .sortedBy { it }
+ .map { it.toUpperCase() }
+ .forEach { print(it) }")))))
+
+(defun next-non-empty-line ()
+ "Moves to the next non-empty line"
+ (forward-line)
+ (while (and (looking-at "^[ \t]*$") (not (eobp)))
+ (forward-line)))
+
+(ert-deftest kotlin-mode--sample-test ()
+ (with-temp-buffer
+ (insert-file-contents "sample.kt")
+ (beginning-of-buffer)
+ (while (not (eobp))
+ (let ((expected-line (thing-at-point 'line)))
-;; (next-line)
-;; (kotlin-mode--indent-line)
+ ;; Remove existing indentation
+ (beginning-of-line)
+ (delete-region (point) (progn (skip-chars-forward " \t") (point)))
-;; (next-line)
-;; (kotlin-mode--indent-line)
+ ;; Indent the line
+ (kotlin-mode--indent-line)
-;; (next-line)
-;; (kotlin-mode--indent-line)
+ ;; Check that the correct indentation is re-applied
+ (should (equal expected-line (thing-at-point 'line)))
-;; (should (equal (buffer-string) "names.filter { it.empty }
-;; .sortedBy { it }
-;; .map { it.toUpperCase() }
-;; .forEach { print(it) }")))))
+ ;; Go to the next non-empty line
+ (next-non-empty-line)
+ )
+ )
+ )
+ )
diff --git a/test/sample.kt b/test/sample.kt
index 069c879711..0e59c5691d 100644
--- a/test/sample.kt
+++ b/test/sample.kt
@@ -105,14 +105,14 @@ if (text in names) // names.contains(text) is called
print("Yes")
names.filter { it.startsWith("A") }
- .sortedBy { it }
- .map { it.toUpperCase() }
- .forEach { print(it) }
+ .sortedBy { it }
+ .map { it.toUpperCase() }
+ .forEach { print(it) }
fun f() {
things.f()
- .g()
- .h()
+ .g()
+ .h()
}
data class Customer(val name: String, val email: String)
@@ -191,18 +191,19 @@ class Turtle {
}
val myTurtle = Turtle()
-with(myTurtle) { //draw a 100 pix square
-penDown()
-for(i in 1..4) {
- forward(100.0)
- turn(90.0)
-}
-penUp()
+with(myTurtle) {
+ //draw a 100 pix square
+ penDown()
+ for(i in 1..4) {
+ forward(100.0)
+ turn(90.0)
+ }
+ penUp()
}
val stream = Files.newInputStream(Paths.get("/some/file.txt"))
-stream.buffered().reader().use { reader ->
- println(reader.readText())
+stream.buffered().reader().use {
+ reader -> println(reader.readText())
}
inline fun <reified T: Any> Gson.fromJson(json): T = this.fromJson(json,
T::class.java)
@@ -718,3 +719,4 @@ fun itpl() {
print("${foo}bar");
print("${`weird$! identifier`}bar");
}
+
- [nongnu] elpa/kotlin-mode ab61099682 152/162: use 4 for defualt tab width, (continued)
- [nongnu] elpa/kotlin-mode ab61099682 152/162: use 4 for defualt tab width, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode e5c6d845e6 093/162: Merge pull request #19 from gregghz/fixes-closing-bracket-indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 72a2bf2347 096/162: Add a file to get Travis-CI to run the test suite., ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode b91bab57b6 099/162: Adding REPL support, credit to https://github.com/sarvex/kotlin-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 1ed0c5589e 098/162: Merge pull request #22 from russel/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 8574583b30 105/162: Fix highlighting escaped identifiers in interpolations, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode eb3704e0e2 106/162: Set adaptive-fill-regexp to comment-start-skip, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 77d709ab54 107/162: Merge pull request #30 from CyberShadow/pull-20180624-142858, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode f08724b978 115/162: Improve handling of bracket-based indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 9fa0d75997 119/162: Tidy up bracked-based indentation into a class, and fix bugs, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 76921927de 117/162: Add a test for correct indentation of sample.kt, and get it to pass (with a few tweaks),
ELPA Syncer <=
- [nongnu] elpa/kotlin-mode 511e0a4ee3 121/162: Add in more kotlin keywords and indent get/set methods for properties, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 21ae667561 126/162: Add highlighted keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode b2d5ff65fc 125/162: Highlight single quotes and back quotes, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode dd24461721 128/162: Add prefix to class methods, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 6aa6d56c0a 131/162: Merge pull request #42 from taku0/add_keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 2f8a57ba64 138/162: Comment out failing emacs versions and link associated bugs, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 3062e14ac0 140/162: Merge pull request #47 from Emacs-Kotlin-Mode-Maintainers/emacs-version-test, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode d8d6461395 145/162: Fix warnings in tests, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 1f60b01659 148/162: Fix indentation of multiline comment at the beginning of buffer, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 9fba76ff2b 155/162: Fix highlighting of backquotes, ELPA Syncer, 2022/01/29