xref: /vim-8.2.3635/runtime/indent/idlang.vim (revision 6e649224)
1" IDL (Interactive Data Language) indent file.
2" Language:	IDL (ft=idlang)
3" Maintainer:	Aleksandar Jelenak <ajelenak AT yahoo.com> (Invalid email address)
4" 		Doug Kearns <[email protected]>
5" Last change:	2017 Jun 13
6
7" Only load this indent file when no other was loaded.
8if exists("b:did_indent")
9   finish
10endif
11let b:did_indent = 1
12
13setlocal indentkeys=o,O,0=endif,0=ENDIF,0=endelse,0=ENDELSE,0=endwhile,0=ENDWHILE,0=endfor,0=ENDFOR,0=endrep,0=ENDREP
14
15setlocal indentexpr=GetIdlangIndent(v:lnum)
16
17" Only define the function once.
18if exists("*GetIdlangIndent")
19   finish
20endif
21
22function GetIdlangIndent(lnum)
23   " First non-empty line above the current line.
24   let pnum = prevnonblank(v:lnum-1)
25   " v:lnum is the first non-empty line -- zero indent.
26   if pnum == 0
27      return 0
28   endif
29   " Second non-empty line above the current line.
30   let pnum2 = prevnonblank(pnum-1)
31
32   " Current indent.
33   let curind = indent(pnum)
34
35   " Indenting of continued lines.
36   if getline(pnum) =~ '\$\s*\(;.*\)\=$'
37      if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
38	 let curind = curind+shiftwidth()
39      endif
40   else
41      if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
42	 let curind = curind-shiftwidth()
43      endif
44   endif
45
46   " Indenting blocks of statements.
47   if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
48      if getline(pnum) =~? 'begin\>'
49      elseif indent(v:lnum) > curind-shiftwidth()
50	 let curind = curind-shiftwidth()
51      else
52	 return -1
53      endif
54   elseif getline(pnum) =~? 'begin\>'
55      if indent(v:lnum) < curind+shiftwidth()
56	 let curind = curind+shiftwidth()
57      else
58	 return -1
59      endif
60   endif
61   return curind
62endfunction
63
64