blob: f7a8b0387ca95c828c93909fba3af28964a0533c [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
dkearns0382f052023-08-29 05:32:59 +10003" 2023 Aug 28 by Vim Project (undo_indent)
Bram Moolenaarc236c162008-07-13 17:41:49 +00004" Language: Logtalk
5
6" This Logtalk indent file is a modified version of the Prolog
7" indent file written by Gergely Kontra
8
9" Only load this indent file when no other was loaded.
10if exists("b:did_indent")
11 finish
12endif
13
14let b:did_indent = 1
15
16setlocal indentexpr=GetLogtalkIndent()
17setlocal indentkeys-=:,0#
18setlocal indentkeys+=0%,-,0;,>,0)
19
dkearns0382f052023-08-29 05:32:59 +100020let b:undo_indent = "setlocal indentexpr< indentkeys<"
21
Bram Moolenaarc236c162008-07-13 17:41:49 +000022" Only define the function once.
23if exists("*GetLogtalkIndent")
24 finish
25endif
26
27function! GetLogtalkIndent()
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 entity opening directive on previous line
43 if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020044 let ind = ind + shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000045 " Check for clause head on previous line
46 elseif pline =~ ':-\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020047 let ind = ind + shiftwidth()
Bram Moolenaard473c8c2018-08-11 18:00:22 +020048 " Check for grammar rule head on previous line
49 elseif pline =~ '-->\s*\(%.*\)\?$'
50 let ind = ind + shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000051 " Check for entity closing directive on previous line
52 elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020053 let ind = ind - shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000054 " Check for end of clause on previous line
55 elseif pline =~ '\.\s*\(%.*\)\?$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020056 let ind = ind - shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000057 endif
58 " Check for opening conditional on previous line
59 if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020060 let ind = ind + shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000061 endif
62 " Check for closing an unclosed paren, or middle ; or ->
63 if line =~ '^\s*\([);]\|->\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020064 let ind = ind - shiftwidth()
Bram Moolenaarc236c162008-07-13 17:41:49 +000065 endif
66 return ind
67endfunction