blob: 66094e3ed0e066574fcca36c97226220a9eddbd8 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" PostScript indent file
Bram Moolenaar6e649222021-10-04 21:32:54 +01002" Language: PostScript
3" Maintainer: Mike Williams <mrw@netcomuk.co.uk> (Invalid email address)
4" Doug Kearns <dougkearns@gmail.com>
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005" Last Change: 2022 Apr 06
6
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
12let b:did_indent = 1
13
14setlocal indentexpr=PostscrIndentGet(v:lnum)
15setlocal indentkeys+=0],0=>>,0=%%,0=end,0=restore,0=grestore indentkeys-=:,0#,e
16
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010017let b:undo_indent = "setl inde< indk<"
18
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" Catch multiple instantiations
20if exists("*PostscrIndentGet")
21 finish
22endif
23
24function! 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*\(%.*\)\=$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020047 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000048 endif
49
50 " Remove indent for popped dicts, and restores.
51 if pline =~ '\(end\|g\=restore\)\s*$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020052 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000053
54 " Else handle immediate dedents of dicts, restores, and arrays.
55 elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020056 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
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
69endfunction
70
71" vim:sw=2