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