blob: 074f467beed0c72dd7d4a9d9b8184dcf1635196f [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar214641f2017-03-05 17:04:09 +01002" Language: Autoconf configure.{ac,in} file
3" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
4" Latest Revision: 2006-12-20
5" TODO: how about nested [()]'s in one line
Bram Moolenaar25394022007-05-10 19:06:20 +00006" what's wrong with '\\\@!'?
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8" Only load this indent file when no other was loaded.
9if exists("b:did_indent")
10 finish
11endif
12
Bram Moolenaar25394022007-05-10 19:06:20 +000013runtime! indent/sh.vim " will set b:did_indent
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
15setlocal indentexpr=GetConfigIndent()
16setlocal indentkeys=!^F,o,O,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
Bram Moolenaar25394022007-05-10 19:06:20 +000017setlocal nosmartindent
Bram Moolenaar071d4272004-06-13 20:20:40 +000018
19" Only define the function once.
20if exists("*GetConfigIndent")
21 finish
22endif
23
24" get the offset (indent) of the end of the match of 'regexp' in 'line'
25function s:GetOffsetOf(line, regexp)
26 let end = matchend(a:line, a:regexp)
27 let width = 0
28 let i = 0
29 while i < end
30 if a:line[i] != "\t"
31 let width = width + 1
32 else
33 let width = width + &ts - (width % &ts)
34 endif
35 let i = i + 1
36 endwhile
37 return width
38endfunction
39
40function GetConfigIndent()
41 " Find a non-blank line above the current line.
42 let lnum = prevnonblank(v:lnum - 1)
43
44 " Hit the start of the file, use zero indent.
45 if lnum == 0
46 return 0
47 endif
48
49 " where to put this
50 let ind = GetShIndent()
51 let line = getline(lnum)
52
53 " if previous line has unmatched, unescaped opening parentheses,
54 " indent to its position. TODO: not failsafe if multiple ('s
55 if line =~ '\\\@<!([^)]*$'
56 let ind = s:GetOffsetOf(line, '\\\@!(')
57 endif
58
59 " if previous line has unmatched opening bracket,
60 " indent to its position. TODO: same as above
61 if line =~ '\[[^]]*$'
62 let ind = s:GetOffsetOf(line, '\[')
63 endif
64
65 " if previous line had an unmatched closing parantheses,
66 " indent to the matching opening parantheses
Bram Moolenaar899dddf2006-03-26 21:06:50 +000067 if line =~ '[^(]\+\\\@<!)$'
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 call search(')', 'bW')
69 let lnum = searchpair('\\\@<!(', '', ')', 'bWn')
70 let ind = indent(lnum)
71 endif
72
73 " if previous line had an unmatched closing bracket,
74 " indent to the matching opening bracket
Bram Moolenaar899dddf2006-03-26 21:06:50 +000075 if line =~ '[^[]\+]$'
Bram Moolenaar071d4272004-06-13 20:20:40 +000076 call search(']', 'bW')
77 let lnum = searchpair('\[', '', ']', 'bWn')
78 let ind = indent(lnum)
79 endif
80
81 return ind
82endfunction