[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode 56ee9b2 359/496: Add comment style option
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode 56ee9b2 359/496: Add comment style option |
Date: |
Sun, 29 Aug 2021 11:34:07 -0400 (EDT) |
branch: elpa/swift-mode
commit 56ee9b21242a055fc9a4f90b5eb666279e50abed
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Add comment style option
Now we can choose multiline comment styles.
Java style:
/**
* Foo
* Bar
*/
Swift Quick Help style:
/**
Foo
Bar
*/
https://developer.apple.com/library/content/documentation/Xcode/Reference/xcode_markup_formatting_ref/index.html
Quick Help style is the default.
Single line comment now inherits spaces from the previous line.
/// - aaa
/// - bbb // When M-j (indent-new-comment-line) is pressed here,
/// // triple spaces will be inserted after slashes.
---
swift-mode-indent.el | 31 ++++++++++++++++++++++---------
test/swift-files/comment.swift | 9 ++++++---
2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index 1d07415..2df9dfe 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -65,6 +65,13 @@
:safe 'integerp)
;;;###autoload
+(defcustom swift-mode:prepend-asterisk-to-comment-line nil
+ "Automatically insert a asterisk to each comment line if non-nil."
+ :type 'boolean
+ :group 'swift
+ :safe 'booleanp)
+
+;;;###autoload
(defcustom swift-mode:insert-space-after-asterisk-in-comment t
"Automatically insert a space after asterisk in comment if non-nil."
:type 'boolean
@@ -1528,7 +1535,11 @@ See `indent-new-comment-line' for SOFT."
(is-single-line-comment (eq (nth 7 parser-state) 1))
(comment-beginning-position (nth 8 parser-state))
(space-after-asterisk
- (if swift-mode:insert-space-after-asterisk-in-comment " " "")))
+ (if swift-mode:insert-space-after-asterisk-in-comment " " ""))
+ (default-line-prefix
+ (if swift-mode:prepend-asterisk-to-comment-line
+ (concat "*" space-after-asterisk)
+ "")))
(delete-horizontal-space)
(if soft (insert-and-inherit ?\n) (newline 1))
(delete-horizontal-space)
@@ -1539,8 +1550,8 @@ See `indent-new-comment-line' for SOFT."
(is-single-line-comment
(save-excursion
(goto-char comment-beginning-position)
- (looking-at "/+")
- (concat (match-string-no-properties 0) space-after-asterisk)))
+ (looking-at "/+\\s *")
+ (match-string-no-properties 0)))
(comment-multi-line
(save-excursion
@@ -1550,13 +1561,14 @@ See `indent-new-comment-line' for SOFT."
(if (<= (point) comment-beginning-position)
;; The cursor was on the 2nd line of the comment.
;; Uses default prefix.
- (concat "*" space-after-asterisk)
+ default-line-prefix
;; The cursor was on the 3nd or following lines of
;; the comment.
;; Use the prefix of the previous line.
(back-to-indentation)
- (if (looking-at "\\*+")
- (concat (match-string-no-properties 0) space-after-asterisk)
+ (if (and swift-mode:prepend-asterisk-to-comment-line
+ (looking-at "\\*+\\s *"))
+ (match-string-no-properties 0)
""))))
(t
@@ -1565,8 +1577,8 @@ See `indent-new-comment-line' for SOFT."
(forward-char)
(save-excursion
(goto-char comment-beginning-position)
- (looking-at "/\\*+")
- (concat (match-string-no-properties 0) space-after-asterisk))))))
+ (looking-at "/\\*+\\s *")
+ (match-string-no-properties 0))))))
(indent-according-to-mode)
;; Closes incomplete multiline comment.
@@ -1585,6 +1597,7 @@ See `indent-new-comment-line' for SOFT."
;; Indents electrically and insert a space when "*" is inserted at the
;; beginning of a line inside a multiline comment.
((and
+ swift-mode:prepend-asterisk-to-comment-line
(= last-command-event ?*)
(nth 4 (syntax-ppss))
(save-excursion (backward-char) (skip-syntax-backward " ") (bolp)))
@@ -1601,7 +1614,7 @@ See `indent-new-comment-line' for SOFT."
(let ((pos (point)))
(beginning-of-line)
(and
- (looking-at "^[ ]*\\*[ ]+/")
+ (looking-at "^\\s *\\*\\s +/")
(eq (match-end 0) pos)
(swift-mode:incomplete-comment-p)))))
(backward-char)
diff --git a/test/swift-files/comment.swift b/test/swift-files/comment.swift
index 8c44d03..0ae6905 100644
--- a/test/swift-files/comment.swift
+++ b/test/swift-files/comment.swift
@@ -7,9 +7,12 @@
// bbb
// ccc
/*
- * aa
- * aa
- * aa
+ aa
+ aa
+ aa
+ - aaa
+ - bbb
+ - ccc
*/
/* */ class Foo {
- [nongnu] elpa/swift-mode 9471669 304/496: Merge taku0/swift3-mode, (continued)
- [nongnu] elpa/swift-mode 9471669 304/496: Merge taku0/swift3-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 848d088 310/496: Fix indentation after attributes with arguments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cad72a1 306/496: Fix a link in README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0a75736 317/496: Fix indentation, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c1f7ec2 321/496: Fix indentation of switch-case body, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7423f68 324/496: Simplify code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 58f31cc 340/496: Speed-up indentation for colon, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0b1f29d 334/496: Fix indentation of setter, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 812d202 341/496: Fix REPL prompt corruption, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f755479 333/496: Fix anchor highlighting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 56ee9b2 359/496: Add comment style option,
ELPA Syncer <=
- [nongnu] elpa/swift-mode dba539e 394/496: Tweak and clean-up font-lock, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode dca378a 400/496: Rename constants, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c532c1e 402/496: Update documents, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d35275b 417/496: Remove unused variables, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8a7be9c 424/496: Use remap for keymap, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 56e21f8 427/496: Simplify autoloads, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 922dc52 445/496: Fix code format, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b260308 451/496: Declare local variables, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 1268425 455/496: Add links to various formatters, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a84f5c8 460/496: Support multi-parttern catch clauses, ELPA Syncer, 2021/08/29