[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
}
}
- [nongnu] elpa/kotlin-mode 4787bf94c1 058/162: Ignore dist folder produce by `cask package`, (continued)
- [nongnu] elpa/kotlin-mode 4787bf94c1 058/162: Ignore dist folder produce by `cask package`, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode d4e97ffa4b 095/162: Switch from using a Bash script to using Make for the tests. Though 'cask exec eert-runner' also works to run the tests., ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode b86f9b4607 147/162: Fix indentation after comment containing close brackets, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode fe905c587a 023/162: kotlin-mode: Highlight classes/enums, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode c91a82b864 031/162: kotlin-mode: Highlight try-`catch-finally', ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 9314dd61f6 040/162: kotlin-mode: Use syntax-propertize-function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 748fcbbec9 049/162: Fix bug in regular expression, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 4f1d0a3919 055/162: Add 'interface' as a type decl keyword, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode e75f8b0113 144/162: Make compatible with Emacs 24.3, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode b9d03a769b 158/162: Add version attribute, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 36b030022e 120/162: Improve identification and handling of line continuation,
ELPA Syncer <=
- [nongnu] elpa/kotlin-mode 639203bf84 143/162: Require cl-lib instead of cl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 8e6dd578f2 154/162: Merge pull request #52 from taku0/add-makefile, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode ffeb70e788 048/162: Temporarily disable syntax highlighting for "by", "get", "set", "in", and "out", ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 86b94d7d34 160/162: Add LICENSE file, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 39db5b6208 033/162: kotlin-mode: Highlight properties, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 300acc2341 036/162: kotlin-mode: Highlight package names, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode a174f5ba44 039/162: kotlin-mode: Add kotlin-mode--match-interpolation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 42b7af8122 046/162: 'data class' -> 'data', ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 6c5531cd6f 059/162: Add autoload cookie to the kotlin-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 876cc27dc1 159/162: Merge pull request #63 from phikal/patch-1, ELPA Syncer, 2022/01/29