@@ -174,54 +174,54 @@ declaration and its offset is `swift-mode:basic-offset'."
174
174
(defun swift-mode:calculate-indent-of-multiline-comment ()
175
175
" Return the indentation of the current line inside a multiline comment."
176
176
(back-to-indentation )
177
- (let ((comment-beginning-position (nth 8 (syntax-ppss )))
177
+ (let ((pos (point ))
178
+ (comment-beginning-position (nth 8 (syntax-ppss )))
178
179
(starts-with-asterisk (eq (char-after ) ?* )))
179
- (forward-line -1 )
180
- (back-to-indentation )
181
180
(cond
182
- ((<= (point ) comment-beginning-position)
183
- ; ; The cursor was on the 2nd line of the comment.
181
+ ; ; Before the closing delimiter.
182
+ ((and (looking-at " \\ *+/" )
183
+ (= pos
184
+ (save-excursion
185
+ (goto-char comment-beginning-position)
186
+ (if (forward-comment 1 )
187
+ (progn
188
+ (backward-char )
189
+ (skip-chars-backward " *" )
190
+ (point ))
191
+ -1 ))))
192
+ ; ; Aligns with the first asterisk of the opening delimiter.
184
193
(goto-char comment-beginning-position)
185
194
(forward-char )
186
- ; ; If there are extra characters or spaces after asterisks, aligns with
187
- ; ; the first non-space character or end of line. Otherwise, aligns with
188
- ; ; the first asterisk.
189
- (when (and
190
- (looking-at " \\ **[^*\n ]+" )
191
- (not (and swift-mode:prepend-asterisk-to-comment-line
192
- starts-with-asterisk)))
193
- (skip-chars-forward " *" )
194
- (skip-syntax-forward " " ))
195
195
(swift-mode:indentation (point ) 0 ))
196
196
197
- ; ; The cursor was on the 3rd or following lines of the comment.
198
-
199
- ((= (save-excursion
200
- (forward-line )
201
- (back-to-indentation )
202
- (point ))
203
- (save-excursion
204
- (goto-char comment-beginning-position)
205
- (if (forward-comment 1 )
206
- (progn
207
- (backward-char )
208
- (skip-chars-backward " *" )
209
- (point ))
210
- -1 )))
211
- ; ; Before the closing delimiter. Aligns with the first asterisk of the
212
- ; ; opening delimiter.
197
+ ; ; The cursor was on the 2nd line of the comment (excluding empty lines).
198
+ ((progn
199
+ (forward-line -1 )
200
+ (while (and (bolp ) (eolp ) (< comment-beginning-position (point )))
201
+ (forward-line -1 ))
202
+ (back-to-indentation )
203
+ (<= (point ) comment-beginning-position))
213
204
(goto-char comment-beginning-position)
214
205
(forward-char )
206
+ ; ; If the line starts with a decoration asterisk, align with the first
207
+ ; ; asterisk of the opening delimiter.
208
+ ; ;
209
+ ; ; Otherwise, if there are extra characters or spaces after asterisks,
210
+ ; ; aligns with the first non-space character or end of line.
211
+ ; ;
212
+ ; ; Otherwise, aligns with the first asterisk of the opening delimiter.
213
+ (when (and
214
+ (not (and swift-mode:prepend-asterisk-to-comment-line
215
+ starts-with-asterisk))
216
+ (looking-at " \\ **[^*\n ]+" ))
217
+ (skip-chars-forward " *" )
218
+ (skip-syntax-forward " " ))
215
219
(swift-mode:indentation (point ) 0 ))
216
220
217
- ; ; Otherwise, aligns with a non-empty preceding line.
218
-
219
- ((and (bolp ) (eolp ))
220
- ; ; The previous line is empty, so seeks a non-empty-line.
221
- (swift-mode:calculate-indent-of-multiline-comment))
222
-
221
+ ; ; The cursor was on the 3rd or following line of the comment, and found a
222
+ ; ; non-empty preceding line.
223
223
(t
224
- ; ; The previous line is not empty, so aligns to this line.
224
+ ; ; Aligns to this line.
225
225
(swift-mode:indentation (point ) 0 )))))
226
226
227
227
(defun swift-mode:calculate-indent-of-multiline-string ()
0 commit comments