7
|
1 " vim: set sw=4 sts=4:
|
|
2 " Maintainer : Gergely Kontra <kgergely@mcl.hu>
|
|
3 " Revised on : 2002.02.18. 23:34:05
|
|
4 " Language : Prolog
|
14864
|
5 " Last change by: Takuya Fujiwara, 2018 Sep 23
|
7
|
6
|
|
7 " TODO:
|
|
8 " checking with respect to syntax highlighting
|
|
9 " ignoring multiline comments
|
|
10 " detecting multiline strings
|
|
11
|
|
12 " Only load this indent file when no other was loaded.
|
|
13 if exists("b:did_indent")
|
|
14 finish
|
|
15 endif
|
|
16
|
|
17 let b:did_indent = 1
|
|
18
|
|
19 setlocal indentexpr=GetPrologIndent()
|
|
20 setlocal indentkeys-=:,0#
|
|
21 setlocal indentkeys+=0%,-,0;,>,0)
|
|
22
|
|
23 " Only define the function once.
|
|
24 "if exists("*GetPrologIndent")
|
|
25 " finish
|
|
26 "endif
|
|
27
|
|
28 function! GetPrologIndent()
|
|
29 " Find a non-blank line above the current line.
|
|
30 let pnum = prevnonblank(v:lnum - 1)
|
|
31 " Hit the start of the file, use zero indent.
|
|
32 if pnum == 0
|
|
33 return 0
|
|
34 endif
|
|
35 let line = getline(v:lnum)
|
|
36 let pline = getline(pnum)
|
|
37
|
|
38 let ind = indent(pnum)
|
|
39 " Previous line was comment -> use previous line's indent
|
|
40 if pline =~ '^\s*%'
|
14864
|
41 return ind
|
|
42 endif
|
|
43 " Previous line was the start of block comment -> +1 after '/*' comment
|
|
44 if pline =~ '^\s*/\*'
|
|
45 return ind + 1
|
|
46 endif
|
|
47 " Previous line was the end of block comment -> -1 after '*/' comment
|
|
48 if pline =~ '^\s*\*/'
|
|
49 return ind - 1
|
7
|
50 endif
|
|
51 " Check for clause head on previous line
|
14864
|
52 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
|
11518
|
53 let ind = ind + shiftwidth()
|
7
|
54 " Check for end of clause on previous line
|
|
55 elseif pline =~ '\.\s*\(%.*\)\?$'
|
11518
|
56 let ind = ind - shiftwidth()
|
7
|
57 endif
|
|
58 " Check for opening conditional on previous line
|
|
59 if pline =~ '^\s*\([(;]\|->\)'
|
11518
|
60 let ind = ind + shiftwidth()
|
7
|
61 endif
|
|
62 " Check for closing an unclosed paren, or middle ; or ->
|
|
63 if line =~ '^\s*\([);]\|->\)'
|
11518
|
64 let ind = ind - shiftwidth()
|
7
|
65 endif
|
|
66 return ind
|
|
67 endfunction
|