vim

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

tf.vim (1604B)


      1 " Vim indent file
      2 " Language:     tf (TinyFugue)
      3 " Maintainer:   Christian J. Robinson <heptite@gmail.com>
      4 " URL:          http://www.vim.org/scripts/script.php?script_id=174
      5 " Last Change:  2022 Apr 25
      6 
      7 " Only load this indent file when no other was loaded.
      8 if exists("b:did_indent")
      9   finish
     10 endif
     11 let b:did_indent = 1
     12 
     13 setlocal indentexpr=GetTFIndent()
     14 setlocal indentkeys-=0{,0} indentkeys-=0# indentkeys-=:
     15 setlocal indentkeys+==/endif,=/then,=/else,=/done,0;
     16 
     17 let b:undo_indent = "setlocal indentexpr< indentkeys<"
     18 
     19 " Only define the function once:
     20 if exists("*GetTFIndent")
     21   finish
     22 endif
     23 
     24 function GetTFIndent()
     25 	" Find a non-blank line above the current line:
     26 	let lnum = prevnonblank(v:lnum - 1)
     27 
     28 	" No indent for the start of the file:
     29 	if lnum == 0
     30 		return 0
     31 	endif
     32 
     33 	let ind = indent(lnum)
     34 	let line = getline(lnum)
     35 
     36 	" No indentation if the previous line didn't end with "\":
     37 	" (Could be annoying, but it lets you know if you made a mistake.)
     38 	if line !~ '\\$'
     39 		return 0
     40 	endif
     41 
     42 	if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$'
     43 		let ind = ind + shiftwidth()
     44 	elseif line =~ '\(/if\|/else\|/then\)'
     45 		if line !~ '/endif'
     46 			let ind = ind + shiftwidth()
     47 		endif
     48 	elseif line =~ '/while'
     49 		if line !~ '/done'
     50 			let ind = ind + shiftwidth()
     51 		endif
     52 	endif
     53 
     54 	let line = getline(v:lnum)
     55 
     56 	if line =~ '\(/else\|/endif\|/then\)'
     57 		if line !~ '/if'
     58 			let ind = ind - shiftwidth()
     59 		endif
     60 	elseif line =~ '/done'
     61 		if line !~ '/while'
     62 			let ind = ind - shiftwidth()
     63 		endif
     64 	endif
     65 
     66 	" Comments at the beginning of a line:
     67 	if line =~ '^\s*;'
     68 		let ind = 0
     69 	endif
     70 
     71 
     72 	return ind
     73 
     74 endfunction