vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

logtalk.vim (1959B)


      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.
     10 if exists("b:did_indent")
     11 	finish
     12 endif
     13 
     14 let b:did_indent = 1
     15 
     16 setlocal indentexpr=GetLogtalkIndent()
     17 setlocal indentkeys-=:,0#
     18 setlocal indentkeys+=0%,-,0;,>,0)
     19 
     20 let b:undo_indent = "setlocal indentexpr< indentkeys<"
     21 
     22 " Only define the function once.
     23 if exists("*GetLogtalkIndent")
     24 	finish
     25 endif
     26 
     27 function! GetLogtalkIndent()
     28 	" Find a non-blank line above the current line.
     29 	let pnum = prevnonblank(v:lnum - 1)
     30 	" Hit the start of the file, use zero indent.
     31 	if pnum == 0
     32 		return 0
     33 	endif
     34 	let line = getline(v:lnum)
     35 	let pline = getline(pnum)
     36 
     37 	let ind = indent(pnum)
     38 	" Previous line was comment -> use previous line's indent
     39 	if pline =~ '^\s*%'
     40 		retu ind
     41 	endif
     42 	" Check for entity opening directive on previous line
     43 	if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$'
     44 		let ind = ind + shiftwidth()
     45 	" Check for clause head on previous line
     46 	elseif pline =~ ':-\s*\(%.*\)\?$'
     47 		let ind = ind + shiftwidth()
     48 	" Check for grammar rule head on previous line
     49 	elseif pline =~ '-->\s*\(%.*\)\?$'
     50 		let ind = ind + shiftwidth()
     51 	" Check for entity closing directive on previous line
     52 	elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$'
     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*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && 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
     67 endfunction