[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/kotlin-mode ff4637c4ea 3/3: Merge pull request #38 from jc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/kotlin-mode ff4637c4ea 3/3: Merge pull request #38 from jcpetkovich/master |
Date: |
Thu, 29 Dec 2022 14:59:12 -0500 (EST) |
branch: elpa/kotlin-mode
commit ff4637c4eaaa6874cebb7de3e2cf5d674fa9c33c
Merge: 55eed95033 0b4291625e
Author: Gregg Hernandez <greggory.hz@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #38 from jcpetkovich/master
More emacs-like indentation.
---
kotlin-mode.el | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 77 insertions(+), 7 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index 201b00691e..6b715a5b4d 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -461,13 +461,83 @@ If it does not exist, will return nil."
(defun kotlin-mode--indent-line ()
"Indent the current line of Kotlin code."
(interactive)
- (indent-line-to (cond
- ((kotlin-mode--first-line-p) 0)
- ((kotlin-mode--in-comment-block)
(kotlin-mode--indent-for-comment))
- (t (kotlin-mode--indent-for-code))
- ))
- (syntax-ppss-flush-cache (point-at-bol))
- )
+ (let ((follow-indentation-p
+ (and (<= (line-beginning-position) (point))
+ (>= (+ (line-beginning-position)
+ (current-indentation))
+ (point)))))
+ (save-excursion
+ (beginning-of-line)
+ (if (bobp) ; 1.)
+ (progn
+ (kotlin-mode--beginning-of-buffer-indent))
+ (let ((not-indented t) cur-indent)
+ (cond ((looking-at "^[ \t]*\\.") ; line starts with .
+ (save-excursion
+ (kotlin-mode--prev-line)
+ (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]*}") ; line starts with }
+ (save-excursion
+ (kotlin-mode--prev-line)
+ (while (and (or (looking-at "^[ \t]*$") (looking-at "^[
\t]*\\.")) (not (bobp)))
+ (kotlin-mode--prev-line))
+ (cond ((or (looking-at ".*{[ \t]*$") (looking-at ".*{.*->[
\t]*$"))
+ (setq cur-indent (current-indentation)))
+ (t
+ (setq cur-indent (- (current-indentation)
kotlin-tab-width)))))
+ (if (< cur-indent 0)
+ (setq cur-indent 0)))
+
+ ((looking-at "^[ \t]*)") ; line starts with )
+ (save-excursion
+ (kotlin-mode--prev-line)
+ (setq cur-indent (- (current-indentation)
kotlin-tab-width)))
+ (if (< cur-indent 0)
+ (setq cur-indent 0)))
+
+ (t
+ (save-excursion
+ (while not-indented
+ (kotlin-mode--prev-line)
+ (cond ((looking-at ".*{[ \t]*$") ; line ends with {
+ (setq cur-indent (+ (current-indentation)
kotlin-tab-width))
+ (setq not-indented nil))
+
+ ((looking-at "^[ \t]*}") ; line starts with }
+ (setq cur-indent (current-indentation))
+ (setq not-indented nil))
+
+ ((looking-at ".*{.*->[ \t]*$") ; line ends with ->
+ (setq cur-indent (+ (current-indentation)
kotlin-tab-width))
+ (setq not-indented nil))
+
+ ((looking-at ".*([ \t]*$") ; line ends with (
+ (setq cur-indent (+ (current-indentation)
kotlin-tab-width))
+ (setq not-indented nil))
+
+ ((looking-at "^[ \t]*).*$") ; line starts with )
+ (setq cur-indent (current-indentation))
+ (setq not-indented nil))
+
+ ((bobp) ; 5.)
+ (setq not-indented nil)))))))
+ (if cur-indent
+ (indent-line-to cur-indent)
+ (indent-line-to 0)))))
+
+ (when follow-indentation-p
+ (back-to-indentation))))
+
+
+(defun kotlin-mode--beginning-of-buffer-indent ()
+ (indent-line-to 0))
;;;###autoload
(define-derived-mode kotlin-mode prog-mode "Kotlin"