9393 " Parent tokens for expressions." )
9494
9595(defun swift-mode:indent-line ()
96+ " Indent the current line."
9697 (let ((indent (save-excursion (swift-mode:calculate-indent)))
9798 (current-indent
9899 (save-excursion (back-to-indentation ) (current-column ))))
103104 (save-excursion (indent-line-to indent)))))
104105
105106(defun swift-mode:calculate-indent ()
107+ " Return the indentation of the current line."
106108 (back-to-indentation )
107109
108110 (if (nth 4 (syntax-ppss ))
115117 (swift-mode:calculate-indent-of-code)))
116118
117119(defun swift-mode:calculate-indent-of-multiline-comment ()
120+ " Return the indentation of the current line inside a multiline comment."
118121 (back-to-indentation )
119122 (let ((comment-beginning-position (nth 8 (syntax-ppss ))))
120123 (forward-line -1 )
134137 (current-column )))))
135138
136139(defun swift-mode:calculate-indent-of-code ()
140+ " Return the indentation of the current line outside multiline comments."
137141 (back-to-indentation )
138142 (let* ((previous-token (save-excursion (swift-mode:backward-token)))
139143 (previous-type (swift-mode:token:type previous-token))
@@ -591,8 +595,7 @@ If scanning stops at eol, align with the next token with BOL-OFFSET.
591595If AFTER-ATTRIBUTES is nil, skip lines with only attributes at the start of
592596the expression."
593597 (save-excursion
594- (let* ((pos (point ))
595- (parent-of-previous-line
598+ (let* ((parent-of-previous-line
596599 (save-excursion
597600 (swift-mode:goto-non-comment-bol-with-same-nesting-level)
598601 (swift-mode:backward-token)))
@@ -1069,12 +1072,12 @@ with one of those token types.
10691072STOP-AT-EOL-TOKEN-TYPES is a list of token types that if we skipped the end of
10701073a line just after a token with one of given toke typen, the function returns.
10711074Typically, this is a list of token types that separates list elements
1072- \( e.g. ',', ';'). If STOP-AT-EOL-TOKEN-TYPES is the symbol `any' , it matches
1075+ \( e.g. ',', ';'). If STOP-AT-EOL-TOKEN-TYPES is the symbol `any' , it matches
10731076all tokens.
10741077STOP-AT-BOL-TOKEN-TYPES is a list of token types that if we hit
10751078the beginning of a line just before a token with one of given token types,
1076- the function returns. Typically, this is a list of token types that starts
1077- list element (e.g. 'case' of switch statement body). If STOP-AT-BOL-TOKEN-TYPES
1079+ the function returns. Typically, this is a list of token types that starts
1080+ list element (e.g. 'case' of switch statement body). If STOP-AT-BOL-TOKEN-TYPES
10781081is the symbol `any' , it matches all tokens."
10791082 (let*
10801083 ((parent (swift-mode:backward-token-or-list))
@@ -1128,6 +1131,7 @@ is the symbol `any', it matches all tokens."
11281131 parent))
11291132
11301133(defun swift-mode:align-with-next-token (parent &optional offset )
1134+ " Return indentation with the PARENT and OFFSET."
11311135 (let ((parent-end (swift-mode:token:end parent)))
11321136 (goto-char parent-end)
11331137 (forward-comment (point-max ))
@@ -1138,6 +1142,7 @@ is the symbol `any', it matches all tokens."
11381142 (+ (or offset 0 ) (current-column ))))
11391143
11401144(defun swift-mode:align-with-current-line (&optional offset )
1145+ " Return indentation of the current line with OFFSET."
11411146 (swift-mode:goto-non-comment-bol)
11421147 (swift-mode:skip-whitespaces)
11431148 (+ (or offset 0 ) (current-column )))
@@ -1275,6 +1280,11 @@ It is a Generic parameter list if:
12751280
12761281(defun swift-mode:try-skip-generic-parameters
12771282 (skip-token-or-list-function matching-bracket-text unmatching-bracket-text)
1283+ " Skip generic parameters if the point is just before/after one.
1284+
1285+ SKIP-TOKEN-OR-LIST-FUNCTION skips forward/backward a token or a list.
1286+ MATCHING-BRACKET-TEXT is a text of the matching bracket.
1287+ UNMATCHING-BRACKET-TEXT is a text of the current bracket."
12781288 (let ((pos (point ))
12791289 (prohibited-tokens (append
12801290 unmatching-bracket-text
@@ -1356,6 +1366,9 @@ Return nil otherwise."
13561366 (skip-syntax-forward " >" ))
13571367
13581368(defun swift-mode:incomplete-comment-p ()
1369+ " Return t if the point is inside an incomplete comment.
1370+
1371+ Return nil otherwise."
13591372 (and (nth 4 (syntax-ppss ))
13601373 (save-excursion
13611374 (goto-char (nth 8 (syntax-ppss )))
@@ -1364,9 +1377,10 @@ Return nil otherwise."
13641377(defun swift-mode:indent-new-comment-line (&optional soft )
13651378 " Break the line at the point and indent the new line.
13661379
1367- If the point is inside a comment, continue the comment. If the comment is a
1380+ If the point is inside a comment, continue the comment. If the comment is a
13681381multiline comment, close the previous comment and start new one if
1369- `comment-multi-line' is nil."
1382+ `comment-multi-line' is nil.
1383+ See `indent-new-comment-line' for SOFT."
13701384 (interactive )
13711385 (let* ((parser-state (syntax-ppss ))
13721386 (is-inside-comment (nth 4 parser-state))
@@ -1422,6 +1436,9 @@ multiline comment, close the previous comment and start new one if
14221436 (indent-according-to-mode )))))
14231437
14241438(defun swift-mode:post-self-insert ()
1439+ " Miscellaneous logic for electric indentation."
1440+ ; ; Indents electrically and insert a space when "*" is inserted at the
1441+ ; ; beginning of a line inside a multiline comment.
14251442 (cond
14261443 ((and
14271444 (= last-command-event ?* )
@@ -1430,6 +1447,8 @@ multiline comment, close the previous comment and start new one if
14301447 (when swift-mode:insert-space-after-asterisk-in-comment
14311448 (insert-before-markers-and-inherit " " ))
14321449 (indent-according-to-mode ))
1450+
1451+ ; ; Fixes "* /" at the end of a multiline comment to "*/".
14331452 ((and
14341453 (= last-command-event ?/ )
14351454 swift-mode:fix-comment-close
0 commit comments