7
|
1 " PostScript indent file
|
|
2 " Language: PostScript
|
|
3 " Maintainer: Mike Williams <mrw@netcomuk.co.uk>
|
|
4 " Last Change: 2nd July 2001
|
|
5 "
|
|
6
|
|
7 " Only load this indent file when no other was loaded.
|
|
8 if exists("b:did_indent")
|
|
9 finish
|
|
10 endif
|
|
11 let b:did_indent = 1
|
|
12
|
|
13 setlocal indentexpr=PostscrIndentGet(v:lnum)
|
|
14 setlocal indentkeys+=0],0=>>,0=%%,0=end,0=restore,0=grestore indentkeys-=:,0#,e
|
|
15
|
|
16 " Catch multiple instantiations
|
|
17 if exists("*PostscrIndentGet")
|
|
18 finish
|
|
19 endif
|
|
20
|
|
21 function! PostscrIndentGet(lnum)
|
|
22 " Find a non-empty non-comment line above the current line.
|
|
23 " Note: ignores DSC comments as well!
|
|
24 let lnum = a:lnum - 1
|
|
25 while lnum != 0
|
|
26 let lnum = prevnonblank(lnum)
|
|
27 if getline(lnum) !~ '^\s*%.*$'
|
|
28 break
|
|
29 endif
|
|
30 let lnum = lnum - 1
|
|
31 endwhile
|
|
32
|
|
33 " Hit the start of the file, use user indent.
|
|
34 if lnum == 0
|
|
35 return -1
|
|
36 endif
|
|
37
|
|
38 " Start with the indent of the previous line
|
|
39 let ind = indent(lnum)
|
|
40 let pline = getline(lnum)
|
|
41
|
|
42 " Indent for dicts, arrays, and saves with possible trailing comment
|
|
43 if pline =~ '\(begin\|<<\|g\=save\|{\|[\)\s*\(%.*\)\=$'
|
11518
|
44 let ind = ind + shiftwidth()
|
7
|
45 endif
|
|
46
|
|
47 " Remove indent for popped dicts, and restores.
|
|
48 if pline =~ '\(end\|g\=restore\)\s*$'
|
11518
|
49 let ind = ind - shiftwidth()
|
7
|
50
|
|
51 " Else handle immediate dedents of dicts, restores, and arrays.
|
|
52 elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
|
11518
|
53 let ind = ind - shiftwidth()
|
7
|
54
|
|
55 " Else handle DSC comments - always start of line.
|
|
56 elseif getline(a:lnum) =~ '^\s*%%'
|
|
57 let ind = 0
|
|
58 endif
|
|
59
|
|
60 " For now catch excessive left indents if they occur.
|
|
61 if ind < 0
|
|
62 let ind = -1
|
|
63 endif
|
|
64
|
|
65 return ind
|
|
66 endfunction
|
|
67
|
|
68 " vim:sw=2
|