emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/kotlin-mode 36b030022e 120/162: Improve identification and


From: ELPA Syncer
Subject: [nongnu] elpa/kotlin-mode 36b030022e 120/162: Improve identification and handling of line continuation
Date: Sat, 29 Jan 2022 08:25:29 -0500 (EST)

branch: elpa/kotlin-mode
commit 36b030022e7139b6bb332b0a9c7cb54d1a879149
Author: Martin Blake <martinblake@github.com>
Commit: Martin Blake <martinblake@github.com>

    Improve identification and handling of line continuation
---
 kotlin-mode.el | 24 ++++++++++++++++++------
 test/sample.kt | 18 +++++++++++++-----
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/kotlin-mode.el b/kotlin-mode.el
index 71b3724cc2..61d7ac643e 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -343,7 +343,11 @@
 
 (defun kotlin-mode--line-continuation()
   "Return whether this line continues a statement in the previous line"
-  (kotlin-mode--line-begins "[\.=:]"))
+  (or
+   (kotlin-mode--line-begins "\\([\.=:]\\|->\\)")
+   (save-excursion
+     (kotlin-mode--prev-line)
+     (kotlin-mode--line-ends "\\([=:]\\|->\\)"))))
 
 (defun kotlin-mode--base-indentation ()
   "Return the indentation level of the current line based on brackets only,
@@ -367,7 +371,11 @@
    (finished :initarg :finished
              :initform nil
              :type boolean
-             :documentation "Whether the counting has finished."))
+             :documentation "Whether the counting has finished.")
+   (use-base :initarg :use-base
+             :initform t
+             :type boolean
+             :documentation "Whether to factor out extra indentations."))
   "A class for counting brackets to find the appropriate bracket-based indent.
    The logic here involves keeping track of the net-bracket-count,
    defined as the number of open-brackets minus the number of close-brackets.
@@ -390,7 +398,9 @@
      ;; If the net-bracket-count is zero, use this indentation
      ((= (oref counter count) 0)
       (oset counter finished t)
-      (add-indent counter (kotlin-mode--base-indentation)))
+      (if (oref counter use-base)
+          (add-indent counter (kotlin-mode--base-indentation))
+        (add-indent counter (current-indentation))))
      ;; If we've now counted more open-brackets than close-brackets,
      ;; use the indentation of the content immediately following the
      ;; final open-bracket.
@@ -406,6 +416,8 @@
 (cl-defmethod count-leading-close-brackets
     ((counter kotlin-mode--bracket-counter))
   "Count any close-bracket at the start of the current line."
+  (if (looking-at "\\s\)")
+      (oset counter use-base nil))
   (subtract-count counter (skip-syntax-forward ")")))
 
 (cl-defmethod count-trailing-open-brackets
@@ -413,8 +425,9 @@
   "If the bracket count is at zero, and there are open-brackets at the end
    of the line, do not count them, but add a single indentation level."
   (if (= (oref counter count) 0)
-      (if (not (= (skip-syntax-backward "(") 0))
-          (add-indent counter kotlin-tab-width))))
+      (cond ((not (= (skip-syntax-backward "(") 0))
+             (add-indent counter kotlin-tab-width)
+             (oset counter use-base nil)))))
 
 (cl-defmethod add-count ((counter kotlin-mode--bracket-counter) val)
   (oset counter count (+ (oref counter count) val)))
@@ -456,7 +469,6 @@
   (beginning-of-line)
   (if (bobp)
       (kotlin-mode--beginning-of-buffer-indent)
-    (kotlin-mode--reset-indentation)
     (let ((cur-indent 0))
       ;; Find bracket-based indentation first
       (let ((bracket-counter (kotlin-mode--bracket-counter)))
diff --git a/test/sample.kt b/test/sample.kt
index 1aeafae5de..2c01e0ed6d 100644
--- a/test/sample.kt
+++ b/test/sample.kt
@@ -303,8 +303,8 @@ class Derived() : Base() {
 }
 
 open class AnotherDerived()
-    : Base() {
-
+    : Base()
+{
     final override fun v() {}
 }
 
@@ -327,7 +327,7 @@ interface B {
 }
 
 class C() : A(), B {
-    // The compiler requires f() to be overridden:
+    // The compiler requires f() to be overridden
     override fun f() {
         super<A>.f() // call to A.f()
         super<B>.f() // call to B.f()
@@ -726,8 +726,16 @@ inline fun <reified T> TreeNode.findParentOfType(): T? {
 }
 
 class Test {
-    fun f() {
-
+    fun tryAdd(a: Int?, b: Int?) : Int? {
+        var result: Int? = null
+        a?.let {
+            lhs ->
+                b?.let {
+                    rhs ->
+                        result = lhs + rhs
+                }
+        }
+        return result
     }
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]