robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ae7ab90159
master
1" Maintainer: Paulo Moura <pmoura@logtalk.org> 2" Revised on: 2018.08.04 3" 2023 Aug 28 by Vim Project (undo_indent) 4" Language: Logtalk 5 6" This Logtalk indent file is a modified version of the Prolog 7" indent file written by Gergely Kontra 8 9" Only load this indent file when no other was loaded. 10if exists ( "b:did_indent" ) 11finish 12endif 13 14let b: did_indent = 1 15 16setlocal indentexpr = GetLogtalkIndent () 17setlocal indentkeys -= :,0# 18setlocal indentkeys += 0%,-,0;,>,0) 19 20let b: undo_indent = "setlocal indentexpr< indentkeys<" 21 22" Only define the function once. 23if exists ( "*GetLogtalkIndent" ) 24finish 25endif 26 27function ! GetLogtalkIndent () 28" Find a non-blank line above the current line. 29let pnum = prevnonblank ( v: lnum - 1 ) 30" Hit the start of the file, use zero indent. 31if pnum == 0 32return 0 33endif 34let line = getline ( v: lnum ) 35let pline = getline ( pnum ) 36 37let ind = indent ( pnum ) 38" Previous line was comment -> use previous line's indent 39if pline =~ '^\s*%' 40retu ind 41endif 42" Check for entity opening directive on previous line 43if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$' 44let ind = ind + shiftwidth () 45" Check for clause head on previous line 46elseif pline =~ ':-\s*\(%.*\)\?$' 47let ind = ind + shiftwidth () 48" Check for grammar rule head on previous line 49elseif pline =~ '-->\s*\(%.*\)\?$' 50let ind = ind + shiftwidth () 51" Check for entity closing directive on previous line 52elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$' 53let ind = ind - shiftwidth () 54" Check for end of clause on previous line 55elseif pline =~ '\.\s*\(%.*\)\?$' 56let ind = ind - shiftwidth () 57endif 58" Check for opening conditional on previous line 59if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)' 60let ind = ind + shiftwidth () 61endif 62" Check for closing an unclosed paren, or middle ; or -> 63if line =~ '^\s*\([);]\|->\)' 64let ind = ind - shiftwidth () 65endif 66return ind 67endfunction