view src/ploki/indent/ploki.vim @ 12292:d51f2100210c draft

<kspalaiologos> `` cat <<<"asmbf && bfi output.b" > /hackenv/ibin/asmbf
author HackEso <hackeso@esolangs.org>
date Thu, 02 Jan 2020 15:38:21 +0000
parents ac0403686959
children
line wrap: on
line source

" Only load this one if no other indent file was loaded.
if exists("b:did_indent")
    finish
endif

let b:did_indent = 1
setlocal indentexpr=GetPlokiIndent()
setlocal indentkeys=!^F,o,O,0=ELSE,0=END\ IF,0=FI,0=KTHX

" Only define the function once.
if exists("*GetPlokiIndent")
    finish
endif

function GetPlokiIndent()
    if v:lnum == 1
		return 0
	endif

	let plnum = v:lnum - 1
	let prevline = getline(plnum)
	while plnum > 0 && prevline =~ '^\s*$'
		let plnum = plnum - 1
		let prevline = getline(plnum)
	endwhile

	let ind = indent(plnum)
	let thisline = getline(v:lnum)

	if prevline =~ '^FOR\%(\s*\S\+\)\@>\%(\s*KTHX\)\@!'
		let ind = ind + &sw
	endif
	if prevline =~ '^\s*\%(FOR\s*\S\+\|\d*\)\s*\%(IF\|ELSE\)'
		let ind = ind + &sw
	endif
	if thisline =~ '^\s*\%(FOR\s*\S\+\|\d*\)\s*\%(ELSE\|END IF\|FI\)'
		let ind = ind - &sw
	elseif ind == &sw && thisline =~ '^\s*\%(\d\+\s*\)\=KTHX'
		let ind = ind - &sw
	endif

	return ind
endfunction