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