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