Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1 | " Maintainer: Paulo Moura <pmoura@logtalk.org> |
Bram Moolenaar | d473c8c | 2018-08-11 18:00:22 +0200 | [diff] [blame] | 2 | " Revised on: 2018.08.04 |
dkearns | 0382f05 | 2023-08-29 05:32:59 +1000 | [diff] [blame] | 3 | " 2023 Aug 28 by Vim Project (undo_indent) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 4 | " 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. |
| 10 | if exists("b:did_indent") |
| 11 | finish |
| 12 | endif |
| 13 | |
| 14 | let b:did_indent = 1 |
| 15 | |
| 16 | setlocal indentexpr=GetLogtalkIndent() |
| 17 | setlocal indentkeys-=:,0# |
| 18 | setlocal indentkeys+=0%,-,0;,>,0) |
| 19 | |
dkearns | 0382f05 | 2023-08-29 05:32:59 +1000 | [diff] [blame] | 20 | let b:undo_indent = "setlocal indentexpr< indentkeys<" |
| 21 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 22 | " Only define the function once. |
| 23 | if exists("*GetLogtalkIndent") |
| 24 | finish |
| 25 | endif |
| 26 | |
| 27 | function! 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 Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 44 | let ind = ind + shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 45 | " Check for clause head on previous line |
| 46 | elseif pline =~ ':-\s*\(%.*\)\?$' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 47 | let ind = ind + shiftwidth() |
Bram Moolenaar | d473c8c | 2018-08-11 18:00:22 +0200 | [diff] [blame] | 48 | " Check for grammar rule head on previous line |
| 49 | elseif pline =~ '-->\s*\(%.*\)\?$' |
| 50 | let ind = ind + shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 51 | " Check for entity closing directive on previous line |
| 52 | elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 53 | let ind = ind - shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 54 | " Check for end of clause on previous line |
| 55 | elseif pline =~ '\.\s*\(%.*\)\?$' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 56 | let ind = ind - shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 57 | endif |
| 58 | " Check for opening conditional on previous line |
| 59 | if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 60 | let ind = ind + shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 61 | endif |
| 62 | " Check for closing an unclosed paren, or middle ; or -> |
| 63 | if line =~ '^\s*\([);]\|->\)' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 64 | let ind = ind - shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 65 | endif |
| 66 | return ind |
| 67 | endfunction |