1" vim: set sw=4 sts=4: 2" Maintainer : Gergely Kontra <[email protected]> 3" Revised on : 2002.02.18. 23:34:05 4" Language : Prolog 5" Last change by: Takuya Fujiwara, 2018 Sep 23 6 7" TODO: 8" checking with respect to syntax highlighting 9" ignoring multiline comments 10" detecting multiline strings 11 12" Only load this indent file when no other was loaded. 13if exists("b:did_indent") 14 finish 15endif 16 17let b:did_indent = 1 18 19setlocal indentexpr=GetPrologIndent() 20setlocal indentkeys-=:,0# 21setlocal indentkeys+=0%,-,0;,>,0) 22 23" Only define the function once. 24"if exists("*GetPrologIndent") 25" finish 26"endif 27 28function! GetPrologIndent() 29 " Find a non-blank line above the current line. 30 let pnum = prevnonblank(v:lnum - 1) 31 " Hit the start of the file, use zero indent. 32 if pnum == 0 33 return 0 34 endif 35 let line = getline(v:lnum) 36 let pline = getline(pnum) 37 38 let ind = indent(pnum) 39 " Previous line was comment -> use previous line's indent 40 if pline =~ '^\s*%' 41 return ind 42 endif 43 " Previous line was the start of block comment -> +1 after '/*' comment 44 if pline =~ '^\s*/\*' 45 return ind + 1 46 endif 47 " Previous line was the end of block comment -> -1 after '*/' comment 48 if pline =~ '^\s*\*/' 49 return ind - 1 50 endif 51 " Check for clause head on previous line 52 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$' 53 let ind = ind + shiftwidth() 54 " Check for end of clause on previous line 55 elseif pline =~ '\.\s*\(%.*\)\?$' 56 let ind = ind - shiftwidth() 57 endif 58 " Check for opening conditional on previous line 59 if pline =~ '^\s*\([(;]\|->\)' 60 let ind = ind + shiftwidth() 61 endif 62 " Check for closing an unclosed paren, or middle ; or -> 63 if line =~ '^\s*\([);]\|->\)' 64 let ind = ind - shiftwidth() 65 endif 66 return ind 67endfunction 68