@@ -282,6 +282,8 @@ and are in fact a sign of run-on. Reserved-symbols not included.")
282
282
nil )
283
283
; ; NO: this line is the start of value body
284
284
; ; ((scala-indent:body-p) ;; TODO did I delete this function when I shouldn't have?
285
+ ; ; TODO or even if I did, maybe it just doesn't matter because the
286
+ ; ; heuristics that union this algorithm with the other will compensate?
285
287
; ; nil)
286
288
; ; YES: eager strategy can stop here, everything is a run-on if no
287
289
; ; counter evidence
@@ -422,6 +424,7 @@ Returns point or (point-min) if not inside a block."
422
424
" A kind of tokenize step of the hand-wavy parse"
423
425
(pcase stack
424
426
; ; <hitting the beginning of a block when starting in the middle> { (
427
+ (`(?\{ ) 'left-boundary ) ; ; too aggressive?
425
428
(`(?\{ , _ . , _ ) 'left-boundary )
426
429
(`(?\( , _ . , _ ) 'left-boundary )
427
430
; ; <dot chaining>
@@ -430,7 +433,7 @@ Returns point or (point-min) if not inside a block."
430
433
; ; =
431
434
(`(= ?\n . , _ ) 'decl-lhs )
432
435
((and `(= , _ . , tail ) (guard (memq ?\n tail))) 'after-decl )
433
- (`(= , _ . , _ ) 'decl-lhs )
436
+ (`(= , _ . , _ ) 'decl-inline- lhs )
434
437
; ; =>
435
438
(`(=> ?\n . , _ ) 'arrow-lhs )
436
439
((and `(=> , _ . , tail ) (guard (memq ?\n tail))) 'after-arrow )
@@ -479,6 +482,8 @@ Returns point or (point-min) if not inside a block."
479
482
(`(override) 'decl )
480
483
; ; package
481
484
(`(package . , _ ) 'decl )
485
+ ; ; sealed
486
+ (`(sealed) 'decl )
482
487
; ; then
483
488
(`(then ?\n . , _ ) 'then-conseq )
484
489
(`(then) 'then )
@@ -520,6 +525,7 @@ Returns point or (point-min) if not inside a block."
520
525
(`(case , _ ) 2 )
521
526
; ; decl
522
527
(`(decl decl) 0 )
528
+ (`(decl decl decl-inline-lhs) 0 )
523
529
(`(decl else) -2 )
524
530
(`(decl . , _ ) 2 )
525
531
; ; decl-lhs
@@ -589,10 +595,19 @@ Returns point or (point-min) if not inside a block."
589
595
(setq stack (cons ?\n stack)))
590
596
; ; (beginning-of-thing 'sexp) gets confused by `.'
591
597
(unless (looking-at-p " \\ ." )
592
- ; ; Avoid double-reading curent symbol
598
+ ; ; Avoid double-reading current symbol
593
599
(beginning-of-thing 'sexp )))
594
- (list (point )
595
- stack))))
600
+ ; ; handle the occurence of case in various contexts
601
+ (or (save-excursion
602
+ (when-let ((_ (looking-at-p (concat " case *"
603
+ scala-syntax:class-or-object-re)))
604
+ (point (progn (forward-to-word 1 ) (point )))
605
+ (class-or-object (sexp-at-point )))
606
+ ; ; This throws away the stack we've built up above. The assumption
607
+ ; ; here is that this case is mutually exclusive with those above.
608
+ (scala-indent:skip-back-over-modifiers point
609
+ (list class-or-object))))
610
+ (list (point ) stack)))))
596
611
597
612
(defun scala-indent:analyze-context (point &optional init-stack )
598
613
" TODO document"
@@ -629,13 +644,19 @@ Returns point or (point-min) if not inside a block."
629
644
(unless result
630
645
(setq last-indentation (current-indentation ))
631
646
(while (looking-at-p " \\ ." ) (backward-char ))
647
+ ; ; ")." is a funny case where we actually do want to be on the dot
648
+ (if (looking-at-p " )" ) (forwar-char))
632
649
(scala-syntax:backward-sexp-forcing)))
633
- (list result
634
- (line-number-at-pos )
635
- (current-indentation )
636
- last-indentation
637
- (point )
638
- stack))))
650
+ (let* ((x (or (scala-indent:skip-back-over-modifiers (point ) stack)
651
+ (list (point ) stack)))
652
+ (point (nth 0 x))
653
+ (stack (nth 1 x)))
654
+ (list result
655
+ (line-number-at-pos )
656
+ (current-indentation )
657
+ last-indentation
658
+ point
659
+ stack)))))
639
660
640
661
(defun scala-indent:full-stmt-less-than-line (syntax-elem stopped-point )
641
662
(and
@@ -657,7 +678,7 @@ Returns point or (point-min) if not inside a block."
657
678
(or (and (= ctxt-line line-no) (> line-no 1 )
658
679
; ; If we keep reading for this reason, we've accepted the
659
680
; ; existing tokens and so need to clear the stack
660
- (list nil ; ; syntax-elem
681
+ (list syntax-elem ; ; syntax-elem
661
682
nil ; ; stack
662
683
(save-excursion ; ; point
663
684
(goto-char stopped-point)
@@ -675,11 +696,29 @@ Returns point or (point-min) if not inside a block."
675
696
; ; We know we have a dot-chain, but we need to get more context to know
676
697
; ; how to position it
677
698
(when (equal syntax-elem '(dot-chain))
678
- (list nil ; ; syntax-elem
699
+ (list syntax-elem ; ; syntax-elem
679
700
nil ; ; stack
680
701
stopped-point ; ; point
681
702
))))
682
703
704
+ (defun scala-indent:skip-back-over-modifiers (point stack )
705
+ (if-let* ((head (car stack))
706
+ (_ (memq head '(trait class object)))
707
+ (new-point point)
708
+ (new-sexp t )
709
+ (new-stack stack))
710
+ (save-excursion
711
+ (goto-char new-point)
712
+ (scala-syntax:backward-sexp-forcing)
713
+ (setq new-sexp (sexp-at-point ))
714
+ (while (memq new-sexp
715
+ '(final sealed case open abstract implicit private))
716
+ (setq new-point (point ))
717
+ (setq new-stack (cons new-sexp new-stack))
718
+ (scala-syntax:backward-sexp-forcing)
719
+ (setq new-sexp (sexp-at-point )))
720
+ (list new-point new-stack))))
721
+
683
722
(defun scala-indent:whitespace-biased-indent (&optional point )
684
723
" Whitespace-syntax-friendly heuristic indentation engine.
685
724
@@ -704,7 +743,7 @@ certain amount of incorrect or in-progress syntactic forms."
704
743
(message " analysis: %s " analysis)
705
744
(while (when-let ((x (scala-indent:continue-lookback?
706
745
syntax-elem ctxt-line line-no stopped-point end-stack)))
707
- (setq syntax-elem (or ( nth 0 x) syntax-elem ))
746
+ (setq syntax-elem (nth 0 x))
708
747
(setq stack (nth 1 x))
709
748
(setq point (nth 2 x))
710
749
t )
0 commit comments