annotate runtime/indent/prolog.vim @ 4143:f5ef9b9c18cd v7.3.824

updated for version 7.3.824 Problem: Can redefine builtin functions. (ZyX) Solution: Disallow adding a function to g:.
author Bram Moolenaar <bram@vim.org>
date Wed, 20 Feb 2013 15:19:43 +0100
parents 3fc0f57ecb91
children 63b0b7b79b25
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 " vim: set sw=4 sts=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Maintainer : Gergely Kontra <kgergely@mcl.hu>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Revised on : 2002.02.18. 23:34:05
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Language : Prolog
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " checking with respect to syntax highlighting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " ignoring multiline comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " detecting multiline strings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentexpr=GetPrologIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 setlocal indentkeys-=:,0#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 setlocal indentkeys+=0%,-,0;,>,0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 "if exists("*GetPrologIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 "endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 function! GetPrologIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 let pnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 if pnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 let line = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let pline = getline(pnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let ind = indent(pnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " Previous line was comment -> use previous line's indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 if pline =~ '^\s*%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 retu ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " Check for clause head on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if pline =~ ':-\s*\(%.*\)\?$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " Check for end of clause on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 elseif pline =~ '\.\s*\(%.*\)\?$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 " Check for opening conditional on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 if pline =~ '^\s*\([(;]\|->\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " Check for closing an unclosed paren, or middle ; or ->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 if line =~ '^\s*\([);]\|->\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 endfunction