robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:partial:cbaff5e06ec5 (#18042)d3068d34cc

master
1.9 KiB71 linesraw
1"  vim: set sw=4 sts=4:
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
6"  Last change by: Takuya Fujiwara, 2018 Sep 23
7"		2022 April: b:undo_indent added by Doug Kearns
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.
15if exists("b:did_indent")
16    finish
17endif
18
19let b:did_indent = 1
20
21setlocal indentexpr=GetPrologIndent()
22setlocal indentkeys-=:,0#
23setlocal indentkeys+=0%,-,0;,>,0)
24
25let b:undo_indent = "setl inde< indk<"
26
27" Only define the function once.
28"if exists("*GetPrologIndent")
29"    finish
30"endif
31
32function! 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*%'
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
54    endif
55    " Check for clause head on previous line
56    if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'
57	let ind = ind + shiftwidth()
58    " Check for end of clause on previous line
59    elseif pline =~ '\.\s*\(%.*\)\?$'
60	let ind = ind - shiftwidth()
61    endif
62    " Check for opening conditional on previous line
63    if pline =~ '^\s*\([(;]\|->\)'
64	let ind = ind + shiftwidth()
65    endif
66    " Check for closing an unclosed paren, or middle ; or ->
67    if line =~ '^\s*\([);]\|->\)'
68	let ind = ind - shiftwidth()
69    endif
70    return ind
71endfunction