Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " vim: set sw=4 sts=4: |
| 2 | " Maintainer : Gergely Kontra <kgergely@mcl.hu> |
| 3 | " Revised on : 2002.02.18. 23:34:05 |
| 4 | " Language : Prolog |
| 5 | |
| 6 | " TODO: |
| 7 | " checking with respect to syntax highlighting |
| 8 | " ignoring multiline comments |
| 9 | " detecting multiline strings |
| 10 | |
| 11 | " Only load this indent file when no other was loaded. |
| 12 | if exists("b:did_indent") |
| 13 | finish |
| 14 | endif |
| 15 | |
| 16 | let b:did_indent = 1 |
| 17 | |
| 18 | setlocal indentexpr=GetPrologIndent() |
| 19 | setlocal indentkeys-=:,0# |
| 20 | setlocal indentkeys+=0%,-,0;,>,0) |
| 21 | |
| 22 | " Only define the function once. |
| 23 | "if exists("*GetPrologIndent") |
| 24 | " finish |
| 25 | "endif |
| 26 | |
| 27 | function! GetPrologIndent() |
| 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 clause head on previous line |
| 43 | if pline =~ ':-\s*\(%.*\)\?$' |
| 44 | let ind = ind + &sw |
| 45 | " Check for end of clause on previous line |
| 46 | elseif pline =~ '\.\s*\(%.*\)\?$' |
| 47 | let ind = ind - &sw |
| 48 | endif |
| 49 | " Check for opening conditional on previous line |
| 50 | if pline =~ '^\s*\([(;]\|->\)' |
| 51 | let ind = ind + &sw |
| 52 | endif |
| 53 | " Check for closing an unclosed paren, or middle ; or -> |
| 54 | if line =~ '^\s*\([);]\|->\)' |
| 55 | let ind = ind - &sw |
| 56 | endif |
| 57 | return ind |
| 58 | endfunction |