Mercurial > hg > dml-home
annotate .vim/indent/prolog.vim @ 3:19d1235ce229
More stigg.
author | samer |
---|---|
date | Sun, 18 Jan 2015 18:35:47 +0000 |
parents | |
children |
rev | line source |
---|---|
samer@3 | 1 " vim: set sw=4 sts=4: |
samer@3 | 2 " Maintainer : Gergely Kontra <kgergely@mcl.hu> |
samer@3 | 3 " Revised on : 2002.02.18. 23:34:05 |
samer@3 | 4 " Language : Prolog |
samer@3 | 5 |
samer@3 | 6 " TODO: |
samer@3 | 7 " checking with respect to syntax highlighting |
samer@3 | 8 " ignoring multiline comments |
samer@3 | 9 " detecting multiline strings |
samer@3 | 10 |
samer@3 | 11 " Only load this indent file when no other was loaded. |
samer@3 | 12 if exists("b:did_indent") |
samer@3 | 13 finish |
samer@3 | 14 endif |
samer@3 | 15 |
samer@3 | 16 let b:did_indent = 1 |
samer@3 | 17 |
samer@3 | 18 setlocal indentexpr=GetPrologIndent() |
samer@3 | 19 setlocal indentkeys-=:,0# |
samer@3 | 20 setlocal indentkeys+=0%,0;,0) |
samer@3 | 21 |
samer@3 | 22 " Only define the function once. |
samer@3 | 23 "if exists("*GetPrologIndent") |
samer@3 | 24 " finish |
samer@3 | 25 "endif |
samer@3 | 26 |
samer@3 | 27 function! GetPrologIndent() |
samer@3 | 28 " Find a non-blank line above the current line. |
samer@3 | 29 let pnum = prevnonblank(v:lnum - 1) |
samer@3 | 30 " Hit the start of the file, use zero indent. |
samer@3 | 31 if pnum == 0 |
samer@3 | 32 return 0 |
samer@3 | 33 endif |
samer@3 | 34 let line = getline(v:lnum) |
samer@3 | 35 let pline = getline(pnum) |
samer@3 | 36 |
samer@3 | 37 let ind = indent(pnum) |
samer@3 | 38 " Previous line was comment -> use previous line's indent |
samer@3 | 39 if pline =~ '^\s*%' |
samer@3 | 40 retu ind |
samer@3 | 41 endif |
samer@3 | 42 " Check for clause head on previous line |
samer@3 | 43 if pline =~ ':-\s*\(%.*\)\?$' |
samer@3 | 44 let ind = ind + &sw |
samer@3 | 45 " Check for end of clause on previous line |
samer@3 | 46 elseif pline =~ '\.\s*\(%.*\)\?$' |
samer@3 | 47 let ind = ind - &sw |
samer@3 | 48 endif |
samer@3 | 49 " Check for opening conditional on previous line |
samer@3 | 50 if pline =~ '^\s*\([(;]\|->\)' |
samer@3 | 51 let ind = ind + &sw |
samer@3 | 52 endif |
samer@3 | 53 " Check for closing an unclosed paren, or middle ; or -> |
samer@3 | 54 if line =~ '^\s*\([);]\|->\)' |
samer@3 | 55 let ind = ind - &sw |
samer@3 | 56 endif |
samer@3 | 57 return ind |
samer@3 | 58 endfunction |