blob: ac03c280649cc3d518015eedb9db95f140eb6e65 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" vim: set sw=4 sts=4:
Bram Moolenaar6e649222021-10-04 21:32:54 +01002" 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
Bram Moolenaar95bafa22018-10-02 13:26:25 +02006" Last change by: Takuya Fujiwara, 2018 Sep 23
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8" TODO:
9" checking with respect to syntax highlighting
10" ignoring multiline comments
11" detecting multiline strings
12
13" Only load this indent file when no other was loaded.
14if exists("b:did_indent")
15 finish
16endif
17
18let b:did_indent = 1
19
20setlocal indentexpr=GetPrologIndent()
21setlocal indentkeys-=:,0#
22setlocal indentkeys+=0%,-,0;,>,0)
23
24" Only define the function once.
25"if exists("*GetPrologIndent")
26" finish
27"endif
28
29function! GetPrologIndent()
30 " Find a non-blank line above the current line.
31 let pnum = prevnonblank(v:lnum - 1)
32 " Hit the start of the file, use zero indent.
33 if pnum == 0
34 return 0
35 endif
36 let line = getline(v:lnum)
37 let pline = getline(pnum)
38
39 let ind = indent(pnum)
40 " Previous line was comment -> use previous line's indent
41 if pline =~ '^\s*%'
Bram Moolenaar95bafa22018-10-02 13:26:25 +020042 return ind
43 endif
44 " Previous line was the start of block comment -> +1 after '/*' comment
45 if pline =~ '^\s*/\*'
46 return ind + 1
47 endif
48 " Previous line was the end of block comment -> -1 after '*/' comment
49 if pline =~ '^\s*\*/'
50 return ind - 1
Bram Moolenaar071d4272004-06-13 20:20:40 +000051 endif
52 " Check for clause head on previous line
Bram Moolenaar95bafa22018-10-02 13:26:25 +020053 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020054 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000055 " Check for end of clause on previous line
56 elseif pline =~ '\.\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020057 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000058 endif
59 " Check for opening conditional on previous line
60 if pline =~ '^\s*\([(;]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020061 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000062 endif
63 " Check for closing an unclosed paren, or middle ; or ->
64 if line =~ '^\s*\([);]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020065 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000066 endif
67 return ind
68endfunction