|
12 | 12 | let b:did_indent = 1 |
13 | 13 |
|
14 | 14 | setlocal indentexpr=GetHaskellIndent() |
15 | | -setlocal indentkeys=!^F,o,O,=wher,=deri,==,0=in,0=class,0=instance,0=data,0=type,0=else,0<bar>,0},0],0(,0),0#,0,0== |
| 15 | +setlocal indentkeys=!^F,o,O,=wher,=deri,==,0=in,0=class,0=instance,0=data,0=type,0=else,0=then,0<bar>,0},0],0(,0),0#,0,0== |
16 | 16 |
|
17 | 17 | let s:save_cpo = &cpo |
18 | 18 | set cpo&vim |
@@ -55,6 +55,11 @@ function! GetHaskellIndent() abort |
55 | 55 | return 0 |
56 | 56 | endif |
57 | 57 |
|
| 58 | + " then |
| 59 | + if line =~# '\v^\s*<then>' |
| 60 | + return s:indent_then() |
| 61 | + endif |
| 62 | + |
58 | 63 | " else |
59 | 64 | if line =~# '\v^\s*<else>' |
60 | 65 | return s:indent_else() |
@@ -454,16 +459,21 @@ function! s:indent_comment() abort |
454 | 459 | return indent(s:prevnonblank(v:lnum - 1)) |
455 | 460 | endfunction |
456 | 461 |
|
| 462 | +" then |
| 463 | +function! s:indent_then() abort |
| 464 | + let [lnum, col] = searchpairpos('\v<if>', '', '\v<then>\zs', 'bnW') |
| 465 | + if lnum == 0 && col == 0 |
| 466 | + return -1 |
| 467 | + else |
| 468 | + " consider adding option to decide where to indent 'then' |
| 469 | + return match(getline(lnum)[col - 1:], '\v<if>\s*\zs') + col - 1 |
| 470 | + endif |
| 471 | +endfunction |
| 472 | + |
457 | 473 | " else |
458 | 474 | function! s:indent_else() abort |
459 | | - let i = s:prevnonblank(v:lnum - 1) |
460 | | - while i > 0 |
461 | | - let line = getline(i) |
462 | | - if line =~# '\v<then>' |
463 | | - return match(line, '\v<then>') |
464 | | - endif |
465 | | - let i = s:prevnonblank(i - 1) |
466 | | - endwhile |
| 475 | + let [lnum, col] = searchpairpos('\v<if>', '\v<then>', '\v<else>\zs', 'bnW') |
| 476 | + return col - 1 |
467 | 477 | endfunction |
468 | 478 |
|
469 | 479 | " | |
|
0 commit comments