blob: 8e36f8611595bac5c416c6ec56e09c0fe3a47bbe [file] [log] [blame]
Bram Moolenaarc236c162008-07-13 17:41:49 +00001" Maintainer: Paulo Moura <pmoura@logtalk.org>
Bram Moolenaard473c8c2018-08-11 18:00:22 +02002" Revised on: 2018.08.04
Bram Moolenaarc236c162008-07-13 17:41:49 +00003" Language: Logtalk
4
5" This Logtalk indent file is a modified version of the Prolog
6" indent file written by Gergely Kontra
7
8" Only load this indent file when no other was loaded.
9if exists("b:did_indent")
10 finish
11endif
12
13let b:did_indent = 1
14
15setlocal indentexpr=GetLogtalkIndent()
16setlocal indentkeys-=:,0#
17setlocal indentkeys+=0%,-,0;,>,0)
18
19" Only define the function once.
20if exists("*GetLogtalkIndent")
21 finish
22endif
23
24function! GetLogtalkIndent()
25 " Find a non-blank line above the current line.
26 let pnum = prevnonblank(v:lnum - 1)
27 " Hit the start of the file, use zero indent.
28 if pnum == 0
29 return 0
30 endif
31 let line = getline(v:lnum)
32 let pline = getline(pnum)
33
34 let ind = indent(pnum)
35 " Previous line was comment -> use previous line's indent
36 if pline =~ '^\s*%'
37 retu ind
38 endif
39 " Check for entity opening directive on previous line
40 if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020041 let ind = ind + shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000042 " Check for clause head on previous line
43 elseif pline =~ ':-\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020044 let ind = ind + shiftwidth()
Bram Moolenaard473c8c2018-08-11 18:00:22 +020045 " Check for grammar rule head on previous line
46 elseif pline =~ '-->\s*\(%.*\)\?$'
47 let ind = ind + shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000048 " Check for entity closing directive on previous line
49 elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020050 let ind = ind - shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000051 " Check for end of clause on previous line
52 elseif pline =~ '\.\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020053 let ind = ind - shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000054 endif
55 " Check for opening conditional on previous line
56 if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020057 let ind = ind + shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000058 endif
59 " Check for closing an unclosed paren, or middle ; or ->
60 if line =~ '^\s*\([);]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020061 let ind = ind - shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000062 endif
63 return ind
64endfunction