@@ -250,7 +250,9 @@ and the empty line")
250
250
(regexp-opt '(" abstract" " catch" " case" " class" " def" " do" " else" " final"
251
251
" finally" " for" " if" " implicit" " import" " lazy" " new" " object"
252
252
" override" " package" " private" " protected" " return" " sealed"
253
- " throw" " trait" " try" " type" " val" " var" " while" " yield" " inline" )
253
+ " throw" " trait" " try" " type" " val" " var" " while" " yield" " inline"
254
+ " extension"
255
+ )
254
256
'words )
255
257
" Words that we don't want to continue the previous line" )
256
258
@@ -370,7 +372,7 @@ is not on a run-on line."
370
372
" \\ |:\\ (" scala-syntax:after-reserved-symbol-re " \\ )" ))
371
373
372
374
(defconst scala-indent:forms-align-re
373
- (regexp-opt '(" yield" " then" " else" " catch" " finally" ) 'words ))
375
+ (regexp-opt '(" do " " yield" " then" " else" " catch" " finally" ) 'words ))
374
376
375
377
(defun scala-indent:forms-align-p (&optional point )
376
378
" Returns `scala-syntax:beginning-of-code-line' for the line on
@@ -434,10 +436,17 @@ Returns point or (point-min) if not inside a block."
434
436
; ; <hitting the beginning of a block when starting in the middle> { (
435
437
(`(?\{ ) 'left-boundary ) ; ; too aggressive?
436
438
(`(?\{ , _ . , _ ) 'left-boundary )
437
- (`(?\( , _ . , _ ) 'left-boundary )
439
+ ; (`(?\( ,_ . ,_) 'left-boundary)
438
440
; ; <dot chaining>
439
441
(`(?\n ?. ) 'dot-chain )
440
442
(`(?\n ?. . , _ ) 'dot-chain )
443
+ ; ; extension
444
+ ; ;
445
+ ; ; FIXME: This is a hack that just checks if the previous line contains
446
+ ; ; extension. The check for extension should check whether this is a
447
+ ; ; single-def extension and for balanced parentheses, etc. to determine
448
+ ; ; whether we emit a block token.
449
+ ((and `(extension . , tail ) (guard (memq ?\n tail))) 'block )
441
450
; ; =
442
451
(`(= ?\n . , _ ) 'decl-lhs )
443
452
((and `(= , _ . , tail ) (guard (memq ?\n tail))) 'after-decl )
@@ -511,6 +520,7 @@ Returns point or (point-min) if not inside a block."
511
520
(`(with) 'block )
512
521
; ; yield
513
522
(`(yield . , _ ) 'yield-from-comp )
523
+ (`(do . , _ ) 'yield-from-comp )
514
524
))
515
525
516
526
(defun scala-indent:relative-indent-by-elem (syntax-elem )
@@ -537,7 +547,7 @@ Returns point or (point-min) if not inside a block."
537
547
(`(decl else) -2 )
538
548
(`(decl . , _ ) 2 )
539
549
; ; decl-lhs
540
- (`(decl-lhs decl . , _ ) 0 )
550
+ (`(decl-lhs decl . , _ ) 2 )
541
551
(`(decl-lhs dot-chain) 4 )
542
552
(`(dot-chain dot-chain) 0 )
543
553
(`(decl-lhs for-comp) 0 )
@@ -653,7 +663,7 @@ Returns point or (point-min) if not inside a block."
653
663
(setq last-indentation (current-indentation ))
654
664
(while (looking-at-p " \\ ." ) (backward-char ))
655
665
; ; ")." is a funny case where we actually do want to be on the dot
656
- (if (looking-at-p " )" ) (forwar -char))
666
+ (if (looking-at-p " )" ) (forward -char ))
657
667
(scala-syntax:backward-sexp-forcing)))
658
668
(let* ((x (or (scala-indent:skip-back-over-modifiers (point ) stack)
659
669
(list (point ) stack)))
@@ -736,10 +746,17 @@ tokenization. The parser is not anything like well-formalized, but it can start
736
746
at an arbitrary point in the buffer, and except in pathological cases, look at
737
747
relatively few lines in order to make a good guess; and it is tolerant to a
738
748
certain amount of incorrect or in-progress syntactic forms."
739
- (let* ((initResult (scala-indent:find-analysis-start point))
749
+ (let* ((line-no
750
+ ; ; Get the line number while taking blanks into account. This allows
751
+ ; ; differentiating between indenting at a blank line and re-indenting
752
+ ; ; at the line right before it.
753
+ (line-number-at-pos
754
+ (save-excursion
755
+ (when point (goto-char point))
756
+ (point ))))
757
+ (initResult (scala-indent:find-analysis-start point))
740
758
(point (car initResult))
741
759
(stack (cadr initResult))
742
- (line-no (line-number-at-pos point))
743
760
(analysis (scala-indent:analyze-context point stack))
744
761
(syntax-elem (list (nth 0 analysis)))
745
762
(ctxt-line (nth 1 analysis))
@@ -756,7 +773,10 @@ certain amount of incorrect or in-progress syntactic forms."
756
773
(setq point (nth 2 x))
757
774
t )
758
775
(setq analysis (scala-indent:analyze-context point stack))
759
- (setq syntax-elem (cons (nth 0 analysis) syntax-elem))
776
+ (setq syntax-elem
777
+ (if (nth 0 analysis)
778
+ (cons (nth 0 analysis) syntax-elem)
779
+ syntax-elem))
760
780
(setq ctxt-line (nth 1 analysis))
761
781
(setq ctxt-indent (nth 2 analysis))
762
782
(setq prev-indent (nth 3 analysis))
0 commit comments