[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/kotlin-mode 2467eceee3 118/162: Properly indent multi-line
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/kotlin-mode 2467eceee3 118/162: Properly indent multi-line comment blocks |
Date: |
Sat, 29 Jan 2022 08:25:29 -0500 (EST) |
branch: elpa/kotlin-mode
commit 2467eceee35725bdc017bb99ff24f31108c2a2dc
Author: Martin Blake <martinblake@github.com>
Commit: Martin Blake <martinblake@github.com>
Properly indent multi-line comment blocks
---
kotlin-mode.el | 45 +++++++++++++++++++++++++++++++++++++++------
test/sample.kt | 6 +++---
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/kotlin-mode.el b/kotlin-mode.el
index cfa8bfc5d1..4edb79ca81 100644
--- a/kotlin-mode.el
+++ b/kotlin-mode.el
@@ -331,6 +331,10 @@
"Return whether the current line ends with the given pattern"
(looking-at (format ".*%s[ \t]*$" pattern)))
+(defun kotlin-mode--line-contains (pattern)
+ "Return whether the current line contains the given pattern"
+ (looking-at (format ".*%s.*" pattern)))
+
(defun kotlin-mode--update-bracket-count (net-count)
"Count the brackets on the current line, incrementing the count
+1 for open-brackets, -1 for close-brackets.
@@ -348,9 +352,12 @@
(defun kotlin-mode--base-indentation ()
"Return the indentation level of the current line based on brackets only,
i.e. ignoring 'continuation' indentation."
- (if (kotlin-mode--line-begins "\\.")
- (- (current-indentation) kotlin-tab-width)
- (current-indentation)))
+ (cond ((kotlin-mode--line-begins "\\.")
+ (- (current-indentation) kotlin-tab-width))
+ ((kotlin-mode--in-comment-block)
+ (- (current-indentation) 1))
+ (t
+ (current-indentation))))
(defun kotlin-mode--post-bracket-indent ()
"Return the indentation at the first non-whitespace character
@@ -374,6 +381,29 @@
(setq position (point))
(- position (re-search-backward "^"))))))
+(defun kotlin-mode--in-comment-block ()
+ "Return whether the cursor is within a standard comment block structure
+ of the following format:
+ /**
+ * Description here
+ */ "
+ (save-excursion
+ (let ((in-comment-block nil)
+ (keep-going (kotlin-mode--line-begins "\\*")))
+ (while keep-going
+ (kotlin-mode--prev-line)
+ (cond
+ ((bobp)
+ (setq keep-going nil))
+ ((kotlin-mode--line-contains "\\*/")
+ (setq keep-going nil))
+ ((kotlin-mode--line-begins "/\\*")
+ (setq keep-going nil)
+ (setq in-comment-block t))
+ ((not (kotlin-mode--line-begins "\\*"))
+ (setq keep-going nil))))
+ in-comment-block)))
+
(defun kotlin-mode--indent-line ()
"Indent current line as kotlin code.
The logic here involves keeping track of the net-bracket-count,
@@ -413,9 +443,12 @@
((bobp)
(setq not-indented nil)))))
- ;; Add extra indentation if the line starts with a period
- (if (kotlin-mode--line-begins "\\.")
- (incf cur-indent kotlin-tab-width))
+ (cond ((kotlin-mode--line-begins "\\.")
+ ;; Add extra indentation if the line starts with a period
+ (incf cur-indent kotlin-tab-width))
+ ((kotlin-mode--in-comment-block)
+ ;; Add one space of extra indentation if inside a comment block
+ (incf cur-indent)))
(if cur-indent
(indent-line-to cur-indent)
diff --git a/test/sample.kt b/test/sample.kt
index 0e59c5691d..e6e2802852 100644
--- a/test/sample.kt
+++ b/test/sample.kt
@@ -6,9 +6,9 @@ import bar.Bar as bBar
// a single line comment
-/*
-* a multiline comment
-*/
+/**
+ * a multiline comment
+ */
fun sum(a: Int, b: Int): Int {
return a + b
- [nongnu] elpa/kotlin-mode e45a8f73e7 061/162: Declare dependency on Emacs 24.3, for setq-local, (continued)
- [nongnu] elpa/kotlin-mode e45a8f73e7 061/162: Declare dependency on Emacs 24.3, for setq-local, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode a02410bc5d 067/162: adds better indentation support for kotlin, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 80f51689bf 074/162: add readme, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 865e55fb4b 072/162: Merge pull request #2 from syohex/fix-package, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode c35ef85b0a 079/162: Merge pull request #2 from rexim/package-improvements, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode c65c96a51a 086/162: fixes close bracket indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode e5ee4c4bd2 094/162: Merge pull request #20 from Thrip/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 6d679ed0da 097/162: Treat use of make as redundant, assume people will use 'cask exec ert-runner' to run the tests., ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode eb7183e47b 101/162: Merge pull request #25 from tninja/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 0e542ae2f7 114/162: Merge pull request #37 from cjfuller/fix-star-projected-types, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 2467eceee3 118/162: Properly indent multi-line comment blocks,
ELPA Syncer <=
- [nongnu] elpa/kotlin-mode 3c48b34e0d 127/162: Delete unused function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 1f57bb5a92 135/162: Fix test runner in .travis.yml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 96b37d211c 139/162: Merge pull request #45 from taku0/add_backup_to_gitignore, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode d9d77ed459 069/162: indentation logic handling lambdas, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 82db4dce0c 077/162: basic indentation test, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 49ef724e96 076/162: additional keywords and smarter highlighting, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode 257647d5d6 083/162: handle chained method calls on multiple lines, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode e1540a5ddf 087/162: Merge pull request #10 from gregghz/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode ad16798e02 091/162: Set proper indentation for closing brackets preceded by a blank line, ELPA Syncer, 2022/01/29
- [nongnu] elpa/kotlin-mode ebcf6f3730 102/162: switch to tab-width, ELPA Syncer, 2022/01/29