branch: elpa/kotlin-mode
commit 257647d5d6afd68c4eaddafeee9057c03b633ed2
Author: Gregg Hernandez <[email protected]>
Commit: Gregg Hernandez <[email protected]>
handle chained method calls on multiple lines
---
kotlin-mode.el | 13 ++++++++++++-
test/kotlin-mode-test.el | 26 ++++++++++++++++++++++++++
test/run-tests.sh | 5 +++++
test/sample.kt | 15 ++++++++++-----
4 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index 4c748de5f4..8ad2f6d9af 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -233,7 +233,18 @@
(progn
(kotlin-mode--beginning-of-buffer-indent))
(let ((not-indented t) cur-indent)
- (cond ((looking-at "^[ \t]*}")
+ (cond ((looking-at "^[ \t]*\\.")
+ (save-excursion
+ (forward-line -1)
+ (cond ((looking-at "^[ \t]*\\.")
+ (setq cur-indent (current-indentation)))
+
+ (t
+ (setq cur-indent (+ (current-indentation) (* 2
kotlin-tab-width)))))
+ (if (< cur-indent 0)
+ (setq cur-indent 0))))
+
+ ((looking-at "^[ \t]*}")
(save-excursion
(forward-line -1)
(setq cur-indent (- (current-indentation) kotlin-tab-width)))
diff --git a/test/kotlin-mode-test.el b/test/kotlin-mode-test.el
index 0ec9a85bbb..c75137cd3b 100644
--- a/test/kotlin-mode-test.el
+++ b/test/kotlin-mode-test.el
@@ -46,3 +46,29 @@ return a + b
(should (equal (buffer-string) "fun sum(a: Int, b: Int): Int {
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) }"))
+
+;; (insert text)
+;; (beginning-of-buffer)
+
+;; (kotlin-mode--indent-line)
+
+;; (next-line)
+;; (kotlin-mode--indent-line)
+
+;; (next-line)
+;; (kotlin-mode--indent-line)
+
+;; (next-line)
+;; (kotlin-mode--indent-line)
+
+;; (should (equal (buffer-string) "names.filter { it.empty }
+;; .sortedBy { it }
+;; .map { it.toUpperCase() }
+;; .forEach { print(it) }")))))
\ No newline at end of file
diff --git a/test/run-tests.sh b/test/run-tests.sh
new file mode 100755
index 0000000000..80faa08d32
--- /dev/null
+++ b/test/run-tests.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+cd ../
+emacs -batch -l ert -l test/kotlin-mode-test.el -f ert-run-tests-batch-and-exit
+cd test
diff --git a/test/sample.kt b/test/sample.kt
index 3edfd5a452..b7bf044c76 100644
--- a/test/sample.kt
+++ b/test/sample.kt
@@ -104,11 +104,16 @@ println(name)
if (text in names) // names.contains(text) is called
print("Yes")
-names
-.filter { it.startsWith("A") }
-.sortedBy { it }
-.map { it.toUpperCase() }
-.forEach { print(it) }
+names.filter { it.startsWith("A") }
+ .sortedBy { it }
+ .map { it.toUpperCase() }
+ .forEach { print(it) }
+
+fun f() {
+ things.f()
+ .g()
+ .h()
+ }
data class Customer(val name: String, val email: String)
val positives = list.filter { x -> x > 0 }