blob: 26a3bc3cd95e1ae52139ed910fea3a34e0df3e72 [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
5
6" TODO:
7" checking with respect to syntax highlighting
8" ignoring multiline comments
9" detecting multiline strings
10
11" Only load this indent file when no other was loaded.
12if exists("b:did_indent")
13 finish
14endif
15
16let b:did_indent = 1
17
18setlocal indentexpr=GetPrologIndent()
19setlocal indentkeys-=:,0#
20setlocal indentkeys+=0%,-,0;,>,0)
21
22" Only define the function once.
23"if exists("*GetPrologIndent")
24" finish
25"endif
26
27function! GetPrologIndent()
28 " Find a non-blank line above the current line.
29 let pnum = prevnonblank(v:lnum - 1)
30 " Hit the start of the file, use zero indent.
31 if pnum == 0
32 return 0
33 endif
34 let line = getline(v:lnum)
35 let pline = getline(pnum)
36
37 let ind = indent(pnum)
38 " Previous line was comment -> use previous line's indent
39 if pline =~ '^\s*%'
40 retu ind
41 endif
42 " Check for clause head on previous line
43 if pline =~ ':-\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020044 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 " Check for end of clause on previous line
46 elseif pline =~ '\.\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020047 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000048 endif
49 " Check for opening conditional on previous line
50 if pline =~ '^\s*\([(;]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020051 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 endif
53 " Check for closing an unclosed paren, or middle ; or ->
54 if line =~ '^\s*\([);]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020055 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000056 endif
57 return ind
58endfunction