annotate runtime/indent/prolog.vim @ 23935:6668c783ba6f

Added tag v8.2.2509 for changeset f9a4ede76237b293b743c37092351457556e0241
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Feb 2021 18:45:05 +0100
parents 40ef13331e02
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 " 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
14864
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
5 " Last change by: Takuya Fujiwara, 2018 Sep 23
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " checking with respect to syntax highlighting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " ignoring multiline comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 " detecting multiline strings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 setlocal indentexpr=GetPrologIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 setlocal indentkeys-=:,0#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 setlocal indentkeys+=0%,-,0;,>,0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 "if exists("*GetPrologIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 "endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 function! GetPrologIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let pnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 if pnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let line = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let pline = getline(pnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let ind = indent(pnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " Previous line was comment -> use previous line's indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if pline =~ '^\s*%'
14864
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
41 return ind
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
42 endif
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
43 " Previous line was the start of block comment -> +1 after '/*' comment
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
44 if pline =~ '^\s*/\*'
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
45 return ind + 1
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
46 endif
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
47 " Previous line was the end of block comment -> -1 after '*/' comment
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
48 if pline =~ '^\s*\*/'
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
49 return ind - 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " Check for clause head on previous line
14864
40ef13331e02 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
52 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
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 " Check for end of clause on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 elseif pline =~ '\.\s*\(%.*\)\?$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
56 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " Check for opening conditional on previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 if pline =~ '^\s*\([(;]\|->\)'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
60 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " Check for closing an unclosed paren, or middle ; or ->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if line =~ '^\s*\([);]\|->\)'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
64 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 endfunction