[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/kotlin-mode 337332287b 1/3: More emacs-like indentation.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/kotlin-mode 337332287b 1/3: More emacs-like indentation. |
Date: |
Thu, 29 Dec 2022 14:59:11 -0500 (EST) |
branch: elpa/kotlin-mode
commit 337332287b65d1b5f1173502864cfce4504f79e4
Author: Jean-Christophe Petkovich <jcpetkovich@gmail.com>
Commit: Jean-Christophe Petkovich <jcpetkovich@gmail.com>
More emacs-like indentation.
---
kotlin-mode.el | 137 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 73 insertions(+), 64 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index 143cc880e4..e5a4b1c41b 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -327,70 +327,79 @@
(defun kotlin-mode--indent-line ()
"Indent current line as kotlin code"
(interactive)
- (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)))))
+ (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 ()