Merge branch 'vim-with-runtime' into feat/quickfix-title
[vim_extended.git] / runtime / indent / postscr.vim
blobb0ff48e682420fde02109a458921e0cffcc0f3e0
1 " PostScript indent file
2 " Language:    PostScript
3 " Maintainer:  Mike Williams <mrw@netcomuk.co.uk>
4 " Last Change: 2nd July 2001
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
13 setlocal indentexpr=PostscrIndentGet(v:lnum)
14 setlocal indentkeys+=0],0=>>,0=%%,0=end,0=restore,0=grestore indentkeys-=:,0#,e
16 " Catch multiple instantiations
17 if exists("*PostscrIndentGet")
18   finish
19 endif
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
33   " Hit the start of the file, use user indent.
34   if lnum == 0
35     return -1
36   endif
38   " Start with the indent of the previous line
39   let ind = indent(lnum)
40   let pline = getline(lnum)
42   " Indent for dicts, arrays, and saves with possible trailing comment
43   if pline =~ '\(begin\|<<\|g\=save\|{\|[\)\s*\(%.*\)\=$'
44     let ind = ind + &sw
45   endif
47   " Remove indent for popped dicts, and restores.
48   if pline =~ '\(end\|g\=restore\)\s*$'
49     let ind = ind - &sw
51   " Else handle immediate dedents of dicts, restores, and arrays.
52   elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
53     let ind = ind - &sw
55   " Else handle DSC comments - always start of line.
56   elseif getline(a:lnum) =~ '^\s*%%'
57     let ind = 0
58   endif
60   " For now catch excessive left indents if they occur.
61   if ind < 0
62     let ind = -1
63   endif
65   return ind
66 endfunction
68 " vim:sw=2