@@ -56,7 +56,8 @@ endfunction
56
56
" Line tokenizer library {{{1
57
57
" ======================
58
58
59
- " Indtokens are "indentation tokens".
59
+ " Indtokens are "indentation tokens". See their exact format in the
60
+ " documentaiton of the s:GetTokensFromLine function.
60
61
61
62
" Purpose:
62
63
" Calculate the new virtual column after the given segment of a line.
@@ -120,8 +121,9 @@ endfunction
120
121
" indtokens = [indtoken]
121
122
" indtoken = [token, vcol, col]
122
123
" token = string (examples: 'begin', '<quoted_atom>', '}')
123
- " vcol = integer (the virtual column of the first character of the token)
124
- " col = integer
124
+ " vcol = integer (the virtual column of the first character of the token;
125
+ " counting starts from 0)
126
+ " col = integer (counting starts from 0)
125
127
function ! s: GetTokensFromLine (line , string_continuation, atom_continuation,
126
128
\t abstop)
127
129
@@ -665,11 +667,14 @@ endfunction
665
667
" stack: [token]
666
668
" token: string
667
669
" stored_vcol: integer
670
+ " lnum: the line number of the "end of clause" mark (or 0 if we hit the
671
+ " beginning of the file)
672
+ " i: the index of the "end of clause" token within its own line
668
673
" Returns:
669
674
" result: [should_return, indent]
670
675
" should_return: bool -- if true, the caller should return `indent` to Vim
671
676
" indent -- integer
672
- function ! s: BeginningOfClauseFound (stack, token, stored_vcol)
677
+ function ! s: BeginningOfClauseFound (stack, token, stored_vcol, lnum, i )
673
678
if ! empty (a: stack ) && a: stack [0 ] == # ' when'
674
679
call s: Log (' BeginningOfClauseFound: "when" found in stack' )
675
680
call s: Pop (a: stack )
@@ -687,13 +692,45 @@ function! s:BeginningOfClauseFound(stack, token, stored_vcol)
687
692
return [1 , a: stored_vcol + &sw ]
688
693
elseif a: stack [0 ] == # ' ;'
689
694
call s: Pop (a: stack )
690
- if empty (a: stack )
691
- call s: Log (' Stack is ["->", ";"], so LTI is in a function head ' .
692
- \' - > return ')
693
- return [0 , a: stored_vcol ]
694
- else
695
+
696
+ if ! empty (a: stack )
695
697
return [1 , s: UnexpectedToken (a: token , a: stack )]
696
698
endif
699
+
700
+ if a: lnum == # 0
701
+ " Set lnum and i to be NextIndToken-friendly
702
+ let lnum = 1
703
+ let i = -1
704
+ else
705
+ let lnum = a: lnum
706
+ let i = a: i
707
+ endif
708
+
709
+ " Are we after a "-spec func() ...;" clause?
710
+ let [next1_indtoken, next1_lnum, next1_i] = s: NextIndToken (lnum, i )
711
+ if ! empty (next1_indtoken) && next1_indtoken[0 ] = ~# ' -'
712
+ let [next2_indtoken, next2_lnum, next2_i] =
713
+ \s : NextIndToken (next1_lnum, next1_i)
714
+ if ! empty (next2_indtoken) && next2_indtoken[0 ] = ~# ' spec'
715
+ let [next3_indtoken, next3_lnum, next3_i] =
716
+ \s : NextIndToken (next2_lnum, next2_i)
717
+ if ! empty (next3_indtoken)
718
+ let [next4_indtoken, next4_lnum, next4_i] =
719
+ \s : NextIndToken (next3_lnum, next3_i)
720
+ if ! empty (next4_indtoken)
721
+ " Yes, we are.
722
+ call s: Log (' Stack is ["->", ";"], so LTI is in a "-spec" ' .
723
+ \' attribute - > return ')
724
+ return [1 , next4_indtoken[1 ]]
725
+ endif
726
+ endif
727
+ endif
728
+ endif
729
+
730
+ call s: Log (' Stack is ["->", ";"], so LTI is in a function head ' .
731
+ \' - > return ')
732
+ return [1 , a: stored_vcol ]
733
+
697
734
else
698
735
return [1 , s: UnexpectedToken (a: token , a: stack )]
699
736
endif
@@ -762,7 +799,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
762
799
" Hit the start of the file
763
800
if lnum == # 0
764
801
let [ret , res ] = s: BeginningOfClauseFound (stack, ' beginning_of_file' ,
765
- \s tored_vcol)
802
+ \s tored_vcol, 0 , 0 )
766
803
if ret | return res | endif
767
804
768
805
return 0
@@ -781,7 +818,8 @@ function! s:ErlangCalcIndent2(lnum, stack)
781
818
endif
782
819
783
820
if token == # ' <end_of_clause>'
784
- let [ret , res ] = s: BeginningOfClauseFound (stack, token, stored_vcol)
821
+ let [ret , res ] = s: BeginningOfClauseFound (stack, token, stored_vcol,
822
+ \l num, i )
785
823
if ret | return res | endif
786
824
787
825
if stored_vcol == # -1
0 commit comments