codekingpro/portable-devtools
114k
1" vim: set sw=4 sts=4:2" Language: Prolog3" Maintainer: Gergely Kontra <kgergely@mcl.hu> (Invalid email address)4" Doug Kearns <dougkearns@gmail.com>5" Revised on: 2002.02.18. 23:34:056" Last change by: Takuya Fujiwara, 2018 Sep 237" 2022 April: b:undo_indent added by Doug Kearns8 9" TODO:10" checking with respect to syntax highlighting11" ignoring multiline comments12" detecting multiline strings13 14" Only load this indent file when no other was loaded.15if exists("b:did_indent")16 finish17endif18 19let b:did_indent = 120 21setlocal indentexpr=GetPrologIndent()22setlocal indentkeys-=:,0#23setlocal indentkeys+=0%,-,0;,>,0)24 25let b:undo_indent = "setl inde< indk<"26 27" Only define the function once.28"if exists("*GetPrologIndent")29" finish30"endif31 32function! GetPrologIndent()33 " Find a non-blank line above the current line.34 let pnum = prevnonblank(v:lnum - 1)35 " Hit the start of the file, use zero indent.36 if pnum == 037 return 038 endif39 let line = getline(v:lnum)40 let pline = getline(pnum)41 42 let ind = indent(pnum)43 " Previous line was comment -> use previous line's indent44 if pline =~ '^\s*%'45 return ind46 endif47 " Previous line was the start of block comment -> +1 after '/*' comment48 if pline =~ '^\s*/\*'49 return ind + 150 endif51 " Previous line was the end of block comment -> -1 after '*/' comment52 if pline =~ '^\s*\*/'53 return ind - 154 endif55 " Check for clause head on previous line56 if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$'57 let ind = ind + shiftwidth()58 " Check for end of clause on previous line59 elseif pline =~ '\.\s*\(%.*\)\?$'60 let ind = ind - shiftwidth()61 endif62 " Check for opening conditional on previous line63 if pline =~ '^\s*\([(;]\|->\)'64 let ind = ind + shiftwidth()65 endif66 " Check for closing an unclosed paren, or middle ; or ->67 if line =~ '^\s*\([);]\|->\)'68 let ind = ind - shiftwidth()69 endif70 return ind71endfunction72 