robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:partial:cbaff5e06ec5 (#18042)d3068d34cc

master
1.7 KiB65 linesraw
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 <dougkearns@gmail.com>
5" Last change:	2022 Apr 06
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
17let b:undo_indent = "setl inde< indk<"
18
19" Only define the function once.
20if exists("*GetIdlangIndent")
21   finish
22endif
23
24function GetIdlangIndent(lnum)
25   " First non-empty line above the current line.
26   let pnum = prevnonblank(v:lnum-1)
27   " v:lnum is the first non-empty line -- zero indent.
28   if pnum == 0
29      return 0
30   endif
31   " Second non-empty line above the current line.
32   let pnum2 = prevnonblank(pnum-1)
33
34   " Current indent.
35   let curind = indent(pnum)
36
37   " Indenting of continued lines.
38   if getline(pnum) =~ '\$\s*\(;.*\)\=$'
39      if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
40	 let curind = curind+shiftwidth()
41      endif
42   else
43      if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
44	 let curind = curind-shiftwidth()
45      endif
46   endif
47
48   " Indenting blocks of statements.
49   if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
50      if getline(pnum) =~? 'begin\>'
51      elseif indent(v:lnum) > curind-shiftwidth()
52	 let curind = curind-shiftwidth()
53      else
54	 return -1
55      endif
56   elseif getline(pnum) =~? 'begin\>'
57      if indent(v:lnum) < curind+shiftwidth()
58	 let curind = curind+shiftwidth()
59      else
60	 return -1
61      endif
62   endif
63   return curind
64endfunction
65