blob: ecd0894166f9348c6535239e08d4799b61f33c80 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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
Bram Moolenaar95bafa22018-10-02 13:26:25 +02005" Last change by: Takuya Fujiwara, 2018 Sep 23
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
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.
13if exists("b:did_indent")
14 finish
15endif
16
17let b:did_indent = 1
18
19setlocal indentexpr=GetPrologIndent()
20setlocal indentkeys-=:,0#
21setlocal indentkeys+=0%,-,0;,>,0)
22
23" Only define the function once.
24"if exists("*GetPrologIndent")
25" finish
26"endif
27
28function! 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*%'
Bram Moolenaar95bafa22018-10-02 13:26:25 +020041 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000050 endif
51 " Check for clause head on previous line
Bram Moolenaar95bafa22018-10-02 13:26:25 +020052 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020053 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000054 " Check for end of clause on previous line
55 elseif pline =~ '\.\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020056 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 endif
58 " Check for opening conditional on previous line
59 if pline =~ '^\s*\([(;]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020060 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 endif
62 " Check for closing an unclosed paren, or middle ; or ->
63 if line =~ '^\s*\([);]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020064 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000065 endif
66 return ind
67endfunction