branch: elpa/kotlin-mode
commit 9e2e4c11fe3a9e8f63ce351762a2b1ac5dbe8a75
Merge: f54da34b3f f42a0745dd
Author: Gregg Hernandez <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #13 from gregghz/whitespace-indent
Ignores blank lines when finding indent level
---
kotlin-mode.el | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index 4f67c027b3..006379cc31 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -225,6 +225,14 @@
t)
(kotlin-mode--match-interpolation limit))))))
+(defun kotlin-mode--prev-line ()
+ "Moves up to the nearest non-empty line"
+ (if (not (bobp))
+ (progn
+ (forward-line -1)
+ (while (and (looking-at "^[ \t]*$") (not (bobp)))
+ (forward-line -1)))))
+
(defun kotlin-mode--indent-line ()
"Indent current line as kotlin code"
(interactive)
@@ -235,7 +243,7 @@
(let ((not-indented t) cur-indent)
(cond ((looking-at "^[ \t]*\\.")
(save-excursion
- (forward-line -1)
+ (kotlin-mode--prev-line)
(cond ((looking-at "^[ \t]*\\.")
(setq cur-indent (current-indentation)))
@@ -246,16 +254,16 @@
((looking-at "^[ \t]*}")
(save-excursion
- (forward-line -1)
+ (kotlin-mode--prev-line)
(while (and (looking-at "^[ \t]*\\.") (not (bobp)))
- (forward-line -1))
+ (kotlin-mode--prev-line))
(setq cur-indent (- (current-indentation) kotlin-tab-width)))
(if (< cur-indent 0)
(setq cur-indent 0)))
((looking-at "^[ \t]*)")
(save-excursion
- (forward-line -1)
+ (kotlin-mode--prev-line)
(setq cur-indent (- (current-indentation) (* 2
kotlin-tab-width))))
(if (< cur-indent 0)
(setq cur-indent 0)))
@@ -263,7 +271,7 @@
(t
(save-excursion
(while not-indented
- (forward-line -1)
+ (kotlin-mode--prev-line)
(cond ((looking-at ".*{[ \t]*$") ; 4.)
(setq cur-indent (+ (current-indentation)
kotlin-tab-width))
(setq not-indented nil))