samer@3: " vim: set sw=4 sts=4: samer@3: " Maintainer : Gergely Kontra samer@3: " Revised on : 2002.02.18. 23:34:05 samer@3: " Language : Prolog samer@3: samer@3: " TODO: samer@3: " checking with respect to syntax highlighting samer@3: " ignoring multiline comments samer@3: " detecting multiline strings samer@3: samer@3: " Only load this indent file when no other was loaded. samer@3: if exists("b:did_indent") samer@3: finish samer@3: endif samer@3: samer@3: let b:did_indent = 1 samer@3: samer@3: setlocal indentexpr=GetPrologIndent() samer@3: setlocal indentkeys-=:,0# samer@3: setlocal indentkeys+=0%,0;,0) samer@3: samer@3: " Only define the function once. samer@3: "if exists("*GetPrologIndent") samer@3: " finish samer@3: "endif samer@3: samer@3: function! GetPrologIndent() samer@3: " Find a non-blank line above the current line. samer@3: let pnum = prevnonblank(v:lnum - 1) samer@3: " Hit the start of the file, use zero indent. samer@3: if pnum == 0 samer@3: return 0 samer@3: endif samer@3: let line = getline(v:lnum) samer@3: let pline = getline(pnum) samer@3: samer@3: let ind = indent(pnum) samer@3: " Previous line was comment -> use previous line's indent samer@3: if pline =~ '^\s*%' samer@3: retu ind samer@3: endif samer@3: " Check for clause head on previous line samer@3: if pline =~ ':-\s*\(%.*\)\?$' samer@3: let ind = ind + &sw samer@3: " Check for end of clause on previous line samer@3: elseif pline =~ '\.\s*\(%.*\)\?$' samer@3: let ind = ind - &sw samer@3: endif samer@3: " Check for opening conditional on previous line samer@3: if pline =~ '^\s*\([(;]\|->\)' samer@3: let ind = ind + &sw samer@3: endif samer@3: " Check for closing an unclosed paren, or middle ; or -> samer@3: if line =~ '^\s*\([);]\|->\)' samer@3: let ind = ind - &sw samer@3: endif samer@3: return ind samer@3: endfunction