blob: 2592bcf62fbdbbadda5cd144e0d8d1f5a05ec3d1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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.
8if exists("b:did_indent")
9 finish
10endif
11let b:did_indent = 1
12
13setlocal indentexpr=PostscrIndentGet(v:lnum)
14setlocal indentkeys+=0],0=>>,0=%%,0=end,0=restore,0=grestore indentkeys-=:,0#,e
15
16" Catch multiple instantiations
17if exists("*PostscrIndentGet")
18 finish
19endif
20
21function! 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*\(%.*\)\=$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020044 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 endif
46
47 " Remove indent for popped dicts, and restores.
48 if pline =~ '\(end\|g\=restore\)\s*$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020049 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
51 " Else handle immediate dedents of dicts, restores, and arrays.
52 elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020053 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
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
66endfunction
67
68" vim:sw=2