@@ -649,6 +649,37 @@ Returns point or (point-min) if not inside a block."
649
649
; ; but that statement took up less than a line
650
650
(> (current-column ) (current-indentation )))))
651
651
652
+ (defun scala-indent:continue-lookback? (syntax-elem
653
+ ctxt-line
654
+ line-no
655
+ stopped-point
656
+ end-stack )
657
+ (or (and (= ctxt-line line-no) (> line-no 1 )
658
+ ; ; If we keep reading for this reason, we've accepted the
659
+ ; ; existing tokens and so need to clear the stack
660
+ (list nil ; ; syntax-elem
661
+ nil ; ; stack
662
+ (save-excursion ; ; point
663
+ (goto-char stopped-point)
664
+ (scala-syntax:backward-sexp-forcing)
665
+ (point ))))
666
+ (when (scala-indent:full-stmt-less-than-line syntax-elem stopped-point)
667
+ ; ; If we read a full statement that was only part of a line,
668
+ ; ; drop it and try again for more context
669
+ (list (cdr syntax-elem) ; ; syntax-elem
670
+ end-stack ; ; restart with the existing stack
671
+ (save-excursion ; ; point
672
+ (goto-char stopped-point)
673
+ (scala-syntax:backward-sexp-forcing)
674
+ (point ))))
675
+ ; ; We know we have a dot-chain, but we need to get more context to know
676
+ ; ; how to position it
677
+ (when (equal syntax-elem '(dot-chain))
678
+ (list nil ; ; syntax-elem
679
+ nil ; ; stack
680
+ stopped-point ; ; point
681
+ ))))
682
+
652
683
(defun scala-indent:whitespace-biased-indent (&optional point )
653
684
" Whitespace-syntax-friendly heuristic indentation engine.
654
685
@@ -670,34 +701,13 @@ certain amount of incorrect or in-progress syntactic forms."
670
701
(stopped-point (nth 4 analysis))
671
702
(end-stack (nth 5 analysis))
672
703
)
673
- (while (or (and (= ctxt-line line-no) (> line-no 1 )
674
- ; ; If we keep reading for this reason, we've accepted the
675
- ; ; existing tokens and so need to clear the stack
676
- (or (setq stack nil )
677
- (setq point
678
- (save-excursion
679
- (goto-char stopped-point)
680
- (scala-syntax:backward-sexp-forcing)
681
- (point )))
682
- t ))
683
- (and (scala-indent:full-stmt-less-than-line syntax-elem stopped-point)
684
- ; ; If we read a full statement that was only part of a line,
685
- ; ; drop it and try again for more context
686
- (or (setq syntax-elem (cdr syntax-elem))
687
- ; ; restart with the existing stack
688
- (setq stack end-stack)
689
- (setq point
690
- (save-excursion
691
- (goto-char stopped-point)
692
- (scala-syntax:backward-sexp-forcing)
693
- (point )))
694
- t ))
695
- ; ; We know we have a dot-chain, but we need to get more context
696
- ; ; to know how to position it
697
- (when (equal syntax-elem '(dot-chain))
698
- (setq stack nil )
699
- (setq point stopped-point)
700
- t ))
704
+ (message " analysis: %s " analysis)
705
+ (while (when-let ((x (scala-indent:continue-lookback?
706
+ syntax-elem ctxt-line line-no stopped-point end-stack)))
707
+ (setq syntax-elem (or (nth 0 x) syntax-elem))
708
+ (setq stack (nth 1 x))
709
+ (setq point (nth 2 x))
710
+ t )
701
711
(setq analysis (scala-indent:analyze-context point stack))
702
712
(setq syntax-elem (cons (nth 0 analysis) syntax-elem))
703
713
(setq ctxt-line (nth 1 analysis))
0 commit comments