xref: /vim-8.2.3635/runtime/indent/prolog.vim (revision 6e649224)
1"  vim: set sw=4 sts=4:
2"  Language:	Prolog
3"  Maintainer:	Gergely Kontra <[email protected]> (Invalid email address)
4" 		Doug Kearns <[email protected]>
5"  Revised on:	2002.02.18. 23:34:05
6"  Last change by: Takuya Fujiwara, 2018 Sep 23
7
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*%'
42	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
51    endif
52    " Check for clause head on previous line
53    if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
54	let ind = ind + shiftwidth()
55    " Check for end of clause on previous line
56    elseif pline =~ '\.\s*\(%.*\)\?$'
57	let ind = ind - shiftwidth()
58    endif
59    " Check for opening conditional on previous line
60    if pline =~ '^\s*\([(;]\|->\)'
61	let ind = ind + shiftwidth()
62    endif
63    " Check for closing an unclosed paren, or middle ; or ->
64    if line =~ '^\s*\([);]\|->\)'
65	let ind = ind - shiftwidth()
66    endif
67    return ind
68endfunction
69