[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/kotlin-mode b86f9b4607 147/162: Fix indentation after comm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/kotlin-mode b86f9b4607 147/162: Fix indentation after comment containing close brackets |
Date: |
Sat, 29 Jan 2022 08:25:31 -0500 (EST) |
branch: elpa/kotlin-mode
commit b86f9b4607ddb0f03a473bf43ef5d85c3e1121e6
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Fix indentation after comment containing close brackets
Example:
```kotlin
fun foo {
bar()
// }
bar() // indenting here
}
```
---
kotlin-mode.el | 19 +++++++++++++------
test/kotlin-mode-test.el | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index 81d5ada482..0c31e91dbd 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -401,13 +401,20 @@ the overall count exceeds zero. If the counter is zero
at the
beginning of the line, Mark the counter finished and set
indentation. If we hit a beginning of line but the counter is
negative, just return without marking finished."
+ (when (nth 4 (syntax-ppss))
+ ;; If the point is inside a comment, goto the beginning of the comment.
+ (goto-char (nth 8 (syntax-ppss))))
(save-excursion
- (while (and (<= (oref counter count) 0) (not (bolp)))
- (backward-char)
- (cond ((looking-at "\\s(")
- (cl-incf (oref counter count)))
- ((looking-at "\\s)")
- (cl-decf (oref counter count)))))
+ (let ((line-beginning-position (line-beginning-position)))
+ (while (and (<= (oref counter count) 0) (not (bolp)))
+ (forward-comment (- (point)))
+ (backward-char)
+ (when (< (point) line-beginning-position)
+ (goto-char line-beginning-position))
+ (cond ((eq (char-syntax (char-after)) ?\()
+ (cl-incf (oref counter count)))
+ ((eq (char-syntax (char-after)) ?\))
+ (cl-decf (oref counter count))))))
;; We are at the beginning of the line, or just before an
;; unmatching open bracket.
(cond
diff --git a/test/kotlin-mode-test.el b/test/kotlin-mode-test.el
index bb2af332e5..bbb39e504d 100644
--- a/test/kotlin-mode-test.el
+++ b/test/kotlin-mode-test.el
@@ -16,7 +16,6 @@ import bar.Bar as bBar
(setq-local kotlin-tab-width 4)
(kotlin-mode--indent-line)
-
(should (equal text (buffer-string)))
(forward-line)
@@ -84,6 +83,40 @@ return a + b
.map { it.toUpperCase() }
.forEach { print(it) }")))))
+(ert-deftest kotlin-mode--ignore-comment-test ()
+ (with-temp-buffer
+ (let ((text "fun foo {
+ bar()
+ // }
+ bar()
+}"))
+ (pop-to-buffer (current-buffer))
+ (insert text)
+ (goto-char (point-min))
+ (kotlin-mode)
+ (setq-local indent-tabs-mode nil)
+ (setq-local tab-width 4)
+ (setq-local kotlin-tab-width 4)
+
+ (kotlin-mode--indent-line)
+ (should (equal text (buffer-string)))
+
+ (forward-line)
+ (kotlin-mode--indent-line)
+ (should (equal text (buffer-string)))
+
+ (forward-line)
+ (kotlin-mode--indent-line)
+ (should (equal text (buffer-string)))
+
+ (forward-line)
+ (kotlin-mode--indent-line)
+ (should (equal text (buffer-string)))
+
+ (forward-line)
+ (kotlin-mode--indent-line)
+ (should (equal text (buffer-string))))))
+
(defun next-non-empty-line ()
"Moves to the next non-empty line"
(forward-line)
- [nongnu] elpa/kotlin-mode d8d6461395 145/162: Fix warnings in tests, (continued)
- [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
- [nongnu] elpa/kotlin-mode 3e0c34087b 162/162: Merge pull request #61 from taku0/make_underbar_symbol, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode cbeeef8986 015/162: kotlin-mode: Define type declaration keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode c6207be613 038/162: kotlin-mode: Add kotin-mode--syntax-propertize-function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 78db8656d4 047/162: Fixed font lock for types, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 1624e7d795 052/162: add 'nested' and 'inner' class modifiers, ELPA Syncer, 2022/01/29
- [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 <=
- [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, 2022/01/29
- [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