aboutsummaryrefslogtreecommitdiff
path: root/dot_vim/indent/indent-r.vim
blob: 30c03c5c5f698d3768670d47ac1ababb5a73441c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
" Vim indent file
" Language:	R
" Author:	Jeremy Stephens <jeremy.f.stephens@vanderbilt.edu>
" URL:		
" Last Change:	
" Version:	
" Notes:  
" Changes: 
" Options: 

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

setlocal indentexpr=GetRIndent()
"setlocal indentkeys+=0=,0),=EO
setlocal indentkeys+=0=,0),=EO,=>

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

function GetRIndent()
	" Find a non-blank line above the current line.
	let lnum = prevnonblank(v:lnum - 1)
	" Hit the start of the file, use zero indent.
	if lnum == 0
		return 0
	endif
    
	let line = getline(lnum)      " last line
	let cline = getline(v:lnum)   " current line
	let pline = getline(lnum - 1) " previous to last line
	let ind = indent(lnum)

	" Indent blocks enclosed by {} or ()
	"if line =~ '[{(]\s*\(#[^)}]*\)\=$'
	if line =~ '[{(]\s*[^)}]*$'
		let ind = ind + &sw
	endif
	if cline =~ '^\s*[)}]'
		let ind = ind - &sw
	endif
    
	return ind
endfunction
" vim: set ts=4 sw=4: