[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/kotlin-mode 04aa6eab91 068/162: handles parens while inden
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/kotlin-mode 04aa6eab91 068/162: handles parens while indenting |
Date: |
Sat, 29 Jan 2022 08:25:23 -0500 (EST) |
branch: elpa/kotlin-mode
commit 04aa6eab91f980fee7e74579e8e502d7f596bec9
Author: Gregg Hernandez <gregg@lucidchart.com>
Commit: Gregg Hernandez <gregg@lucidchart.com>
handles parens while indenting
---
kotlin-mode.el | 70 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 38 insertions(+), 32 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index 331bf5a4e9..6dcaadce9b 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -211,49 +211,55 @@
t)
(kotlin-mode--match-interpolation limit))))))
-;; Indentation rules
-;; 1.) If we are at the beginning of the buffer, indent to column 0
-;; 2.) If we are currently at an `}' line, then de-indent relative to the
previous line
-;; 3.) If we _first_ see an `}' line before out current line, then we should
indent our current line to the same indentation as the `}' line.
-;; 4.) If we _first_ see a "start line" like `if (true) {', then we need to
_increase_ out indentation relative to that start line.
-;; 5.) If none of the above apply, then do not indent at all.
(defun kotlin-mode--indent-line ()
"Indent current line as kotlin code"
(interactive)
+ (beginning-of-line)
(if (bobp) ; 1.)
(progn
- (message "Rule 1.")
(kotlin-mode--beginning-of-buffer-indent))
(let ((not-indented t) cur-indent)
- (if (looking-at "^[ \t]*}") ; 2.)
- (progn
- (message "Rule 2.")
- (save-excursion
- (forward-line -1)
- (setq cur-indent (- (current-indentation) default-tab-width)))
- (if (< cur-indent 0)
- (setq cur-indent 0)))
- (save-excursion
- (while not-indented
- (forward-line -1)
- (if (looking-at "^[ \t]*}") ; 3.)
- (progn
- (message "Rule 3.")
- (setq cur-indent (current-indentation))
- (setq not-indented nil))
- (if (looking-at ".*{[ \t]*$") ; 4.)
- (progn
- (message "Rule 4.")
- (setq cur-indent (+ (current-indentation)
default-tab-width))
- (setq not-indented nil))
- (if (bobp) ; 5.)
- (progn
- (message "Rule 5.")
- (setq not-indented nil))))))))
+ (cond ((looking-at "^[ \t]*}")
+ (save-excursion
+ (forward-line -1)
+ (setq cur-indent (- (current-indentation) default-tab-width)))
+ (if (< cur-indent 0)
+ (setq cur-indent 0)))
+
+ ((looking-at "^[ \t]*)")
+ (save-excursion
+ (forward-line -1)
+ (setq cur-indent (- (current-indentation) (* 2
default-tab-width))))
+ (if (< cur-indent 0)
+ (setq cur-indent 0)))
+
+ (t
+ (save-excursion
+ (while not-indented
+ (forward-line -1)
+ (cond ((looking-at "^[ \t]*}") ; 3.)
+ (setq cur-indent (current-indentation))
+ (setq not-indented nil))
+
+ ((looking-at ".*{[ \t]*$") ; 4.)
+ (setq cur-indent (+ (current-indentation)
default-tab-width))
+ (setq not-indented nil))
+
+ ((looking-at ".*([ \t]*$")
+ (setq cur-indent (+ (current-indentation) (* 2
default-tab-width)))
+ (setq not-indented nil))
+
+ ((looking-at "^[ \t]*).*$")
+ (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)))))
+
(defun kotlin-mode--beginning-of-buffer-indent ()
(indent-line-to 0))
- [nongnu] elpa/kotlin-mode 81a49e95e6 011/162: kotlin-mode: Add kotlin-mode-font-keywords, (continued)
- [nongnu] elpa/kotlin-mode 81a49e95e6 011/162: kotlin-mode: Add kotlin-mode-font-keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode ea74bb577a 016/162: kotlin-mode: Define function declaration keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 20dca19dba 009/162: kotlin-mode: syntax-table - Define strings, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 0c7ca08d99 018/162: kotlin-mode: Define statement keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode d801f5c5cf 020/162: kotlin-mode: Define keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode d2436b8763 013/162: Cask: Use rx, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 56cfb15910 029/162: kotlin-mode: Highlight function names, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 6cfa5b71cf 032/162: kotlin-mode: Define property keywords, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 70d36a45c9 051/162: Add comment syntax, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode ffd69308ab 056/162: Handle all typedecl keywords the same way, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 04aa6eab91 068/162: handles parens while indenting,
ELPA Syncer <=
- [nongnu] elpa/kotlin-mode 81b869a98c 075/162: consistent naming, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 34d89566b4 084/162: First stab at a README., ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 9e2e4c11fe 090/162: Merge pull request #13 from gregghz/whitespace-indent, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode a2c2628d55 104/162: Merge pull request #27 from trevorsummerssmith/more-focus, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 5d83221994 109/162: 1x indent inside parenthesis, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 41eaed3e38 116/162: Remove overwritten <tab> key mapping so that region indentation works, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 5e9aff2ae9 122/162: Fix tests to run in the expected test environment., ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 7de9cc101a 133/162: Add *.elc to .gitignore, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 42fa1402a1 150/162: Merge pull request #49 from taku0/fix-warnings, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 0e4bafb31d 156/162: Merge pull request #57 from taku0/fix-backquote, ELPA Syncer, 2022/01/29