branch: elpa/swift-mode commit 56ee9b21242a055fc9a4f90b5eb666279e50abed Author: taku0 <mxxouy6x3m_git...@tatapa.org> Commit: taku0 <mxxouy6x3m_git...@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 {