dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

rcshell.vim (1404B)


      1 " Vim indent file
      2 " Language:	rc
      3 " Maintainer:	hhvn <dev@hhvn.uk>
      4 " License:	This file is placed in the public domain.
      5 "
      6 " Written by hhvn.
      7 
      8 if exists("b:did_indent")
      9 	finish
     10 endif
     11 let b:did_indent = 1
     12 
     13 setlocal indentexpr=GetRcIndent()
     14 setlocal indentkeys+=0},0)
     15 setlocal nosmartindent
     16 
     17 if exists("GetRcIndent")
     18 	finish
     19 endif
     20 
     21 function! GetRcIndent()
     22 	let curline = getline(v:lnum)
     23 	let lnum = prevnonblank(v:lnum - 1)
     24 	let pnum = prevnonblank(lnum - 1)
     25 
     26 	if lnum == 0
     27 		return 0
     28 	endif
     29 
     30 	let prevline = getline(pnum)
     31 	let line = getline(lnum)
     32 	let indent = indent(lnum)
     33 	let origindent = indent
     34 
     35 	if curline =~ '[})]'
     36 		let prevline = line
     37 		let line = curline
     38 	endif
     39 
     40 	let braces = s:Get_brace_balance(line, '{', '}')
     41 	if braces < 0
     42 		let braces += 1
     43 	endif
     44 	let indent += braces * &sw
     45 
     46 	let braces = s:Get_brace_balance(line, '(', ')')
     47 	if braces < 0
     48 		let braces += 1
     49 	endif
     50 	let indent += braces * &sw
     51 
     52 	if line =~ '[|\\]\s*$'
     53 		if prevline =~ '[|\\]\s*$'
     54 			let indent += 0
     55 		elseif origindent == indent
     56 			let indent += &sw
     57 		endif
     58 	endif
     59 
     60 	return indent
     61 endfunction
     62 
     63 " Taken from awk indenter
     64 function! s:Get_brace_balance( line, b_open, b_close )
     65    let line2 = substitute( a:line, a:b_open, "", "g" )
     66    let openb = strlen( a:line ) - strlen( line2 )
     67    let line3 = substitute( line2, a:b_close, "", "g" )
     68    let closeb = strlen( line2 ) - strlen( line3 )
     69    return openb - closeb
     70 endfunction