@@ -407,15 +407,15 @@ declaration and its offset is `swift-mode:basic-offset'."
407407 '(" switch" ) nil '(" case" " default" ))))
408408 (if (equal (swift-mode:token:text parent) " switch" )
409409 ; ; Inside a switch-statement. Aligns with the "switch"
410- (swift-mode:find-and-align-with-parents
410+ (swift-mode:find-parent- and-align-with-next
411411 swift-mode:statement-parent-tokens
412412 swift-mode:switch-case-offset)
413413 ; ; Other cases. Aligns with the previous case.
414414 (swift-mode:align-with-current-line))))
415415
416416 ; ; After "catch"
417417 ((equal previous-text " catch" )
418- (swift-mode:find-and-align-with-parents
418+ (swift-mode:find-parent- and-align-with-next
419419 swift-mode:statement-parent-tokens
420420 swift-mode:multiline-statement-offset))
421421
@@ -476,7 +476,7 @@ declaration and its offset is `swift-mode:basic-offset'."
476476 ; ; in
477477 ; ; a
478478 ; ; }
479- (swift-mode:find-and-align-with-parents '(" for" {)))
479+ (swift-mode:find-parent- and-align-with-next '(" for" {)))
480480
481481 ; ; Before "where" on the current line
482482 ((and next-is-on-current-line (equal next-text " where" ))
@@ -542,9 +542,9 @@ declaration and its offset is `swift-mode:basic-offset'."
542542 swift-mode:multiline-statement-offset
543543 swift-mode:multiline-statement-offset))
544544 ((equal (swift-mode:token:text parent) " for" )
545- (swift-mode:find-and-align-with-parents '(" for" )))
545+ (swift-mode:find-parent- and-align-with-next '(" for" )))
546546 (t
547- (swift-mode:find-and-align-with-parents
547+ (swift-mode:find-parent- and-align-with-next
548548 (append swift-mode:statement-parent-tokens '(< ))
549549 swift-mode:multiline-statement-offset)))))
550550
@@ -628,14 +628,14 @@ declaration and its offset is `swift-mode:basic-offset'."
628628 (swift-mode:calculate-indent-of-expression
629629 swift-mode:multiline-statement-offset
630630 swift-mode:multiline-statement-offset))
631- (swift-mode:find-and-align-with-parents
631+ (swift-mode:find-parent- and-align-with-next
632632 (append swift-mode:statement-parent-tokens '(< " for" ))
633633 swift-mode:multiline-statement-offset)))))
634634
635635 ; ; After implicit-\; or ;
636636 ((memq previous-type '(implicit-\; \; ))
637637 (goto-char (swift-mode:token:start previous-token))
638- (swift-mode:find-and-align-with-parents
638+ (swift-mode:find-parent- and-align-with-next
639639 (remove '\; (remove 'implicit- \; swift-mode:statement-parent-tokens))
640640 0
641641 '(implicit-\; \; )))
@@ -677,20 +677,20 @@ declaration and its offset is `swift-mode:basic-offset'."
677677 ; ; After case ... : or default:
678678 ((eq previous-type 'case-: )
679679 (goto-char (swift-mode:token:start previous-token))
680- (swift-mode:find-and-align-with-parents
680+ (swift-mode:find-parent- and-align-with-next
681681 swift-mode:statement-parent-tokens
682682 (- swift-mode:basic-offset swift-mode:switch-case-offset)))
683683
684684 ; ; Before ; on the current line
685685 ((and next-is-on-current-line (eq next-type '\; ))
686- (swift-mode:find-and-align-with-parents
686+ (swift-mode:find-parent- and-align-with-next
687687 (remove '\; (remove 'implicit- \; swift-mode:statement-parent-tokens))
688688 0
689689 '(implicit-\; \; )))
690690
691691 ; ; After if, guard, and while
692692 ((member previous-text '(" if" " guard" " while" ))
693- (swift-mode:find-and-align-with-parents
693+ (swift-mode:find-parent- and-align-with-next
694694 swift-mode:statement-parent-tokens
695695 swift-mode:multiline-statement-offset))
696696
@@ -710,14 +710,17 @@ declaration and its offset is `swift-mode:basic-offset'."
710710 (swift-mode:calculate-indent-of-expression
711711 swift-mode:multiline-statement-offset)))))
712712
713- (defun swift-mode:find-and-align-with-parents
713+ (defun swift-mode:find-parent- and-align-with-next
714714 (parents
715715 &optional
716716 offset
717717 stop-at-eol-token-types
718718 stop-at-bol-token-types
719719 bol-offset)
720- " Return start column of the current expressions or statement plus offset.
720+ " Find the parent and return indentation based on it.
721+
722+ A parent is, for example, the open bracket of the containing block or
723+ semicolon of the preceding statement.
721724
722725PARENTS is a list of token types that precedes an expression or a statement.
723726OFFSET is the offset. If it is omitted, assumed to be 0.
@@ -727,8 +730,9 @@ If scanning stops at STOP-AT-EOL-TOKEN-TYPES, align with the next token with
727730BOL-OFFSET.
728731If scanning stops at STOP-AT-BOL-TOKEN-TYPES, align with that token with
729732BOL-OFFSET.
730- If STOP-AT-BOL-TOKEN-TYPES is the symbol `any' , the cursor is assumed to be
731- on the previous line."
733+ If STOP-AT-BOL-TOKEN-TYPES or STOP-AT-BOL-TOKEN-TYPES is the symbol
734+ `any' , it matches all tokens.
735+ The point is assumed to be on the previous line."
732736 (save-excursion
733737 (let* ((parent (swift-mode:backward-sexps-until
734738 parents
@@ -749,25 +753,19 @@ on the previous line."
749753 stop-at-eol-token-types)
750754 (member (swift-mode:token:text parent)
751755 stop-at-eol-token-types)))))
752- (when (or stopped-at-parent stopped-at-eol)
753- (goto-char parent-end)
754- (forward-comment (point-max )))
755- ; ; Now, the cursor is at the first token of the expression.
756-
757756 (if stopped-at-parent
758- ; ; The cursor is at the start of the entire expression.
759- ; ; Aligns with the start of the expression with offset.
760757 (swift-mode:align-with-next-token parent offset)
761- ; ; The cursor is at the middle of the expression.
762- ; ; Aligns with this line with bol-offset.
758+ (when stopped-at-eol
759+ (goto-char parent-end)
760+ (forward-comment (point-max )))
763761 (swift-mode:align-with-current-line bol-offset)))))
764762
765763(defun swift-mode:calculate-indent-of-expression
766764 (&optional
767765 offset
768766 bol-offset
769767 after-attributes)
770- " Return start column of the current expressions plus offset .
768+ " Return indentation of the current expression .
771769
772770the cursor is assumed to be on the previous line.
773771
@@ -975,7 +973,7 @@ This function is also used for close-curly-brace."
975973 (setq next-token (swift-mode:forward-token-or-list))
976974 (goto-char (1+ pos))))))))
977975 (if is-declaration-or-control-statement-body
978- (swift-mode:find-and-align-with-parents
976+ (swift-mode:find-parent- and-align-with-next
979977 swift-mode:statement-parent-tokens
980978 offset)
981979 (swift-mode:calculate-indent-of-expression offset offset))))
@@ -1487,7 +1485,7 @@ SKIP-TOKEN-OR-LIST-FUNCTION skips forward/backward a token or a list.
14871485MATCHING-BRACKET-TEXT is a text of the matching bracket.
14881486UNMATCHING-BRACKET-TEXT is a text of the current bracket."
14891487 (let ((pos (point ))
1490- (prohibited-tokens (append
1488+ (prohibited-tokens (cons
14911489 unmatching-bracket-text
14921490 swift-mode:tokens-not-in-generic-parameter-list))
14931491 (next-token (funcall skip-token-or-list-function)))
0 commit comments