annotate runtime/indent/postscr.vim @ 15464:3faa7cc8207c v8.1.0740

patch 8.1.0740: Tcl test fails commit https://github.com/vim/vim/commit/8309b0559da6e9a581a7816572594c90c2d7f942 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 13 16:46:22 2019 +0100 patch 8.1.0740: Tcl test fails Problem: Tcl test fails. Solution: When the argument is empty don't give an error, instead rely on the error reporting higher up.
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Jan 2019 17:00:06 +0100
parents 63b0b7b79b25
children 9c221ad9634a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " PostScript indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: PostScript
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Mike Williams <mrw@netcomuk.co.uk>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Last Change: 2nd July 2001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentexpr=PostscrIndentGet(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal indentkeys+=0],0=>>,0=%%,0=end,0=restore,0=grestore indentkeys-=:,0#,e
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " Catch multiple instantiations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 if exists("*PostscrIndentGet")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 function! PostscrIndentGet(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Find a non-empty non-comment line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Note: ignores DSC comments as well!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 let lnum = a:lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 while lnum != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let lnum = prevnonblank(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 if getline(lnum) !~ '^\s*%.*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " Hit the start of the file, use user indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " Start with the indent of the previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let pline = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " Indent for dicts, arrays, and saves with possible trailing comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if pline =~ '\(begin\|<<\|g\=save\|{\|[\)\s*\(%.*\)\=$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
44 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 " Remove indent for popped dicts, and restores.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if pline =~ '\(end\|g\=restore\)\s*$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
49 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " Else handle immediate dedents of dicts, restores, and arrays.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
53 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " Else handle DSC comments - always start of line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 elseif getline(a:lnum) =~ '^\s*%%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 let ind = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " For now catch excessive left indents if they occur.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 if ind < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 let ind = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 " vim:sw=2