aboutsummaryrefslogtreecommitdiff
path: root/dot_vim/indent/indent-r.vim
diff options
context:
space:
mode:
authorRyan Kavanagh <rak@rak.ac>2021-12-13 16:55:42 -0500
committerRyan Kavanagh <rak@rak.ac>2021-12-13 16:58:10 -0500
commite5dfb045b994e1ab8fef9ef5d3f02ce20ea6b685 (patch)
treeba74287d80e46c70dab8c4311a1dc933fbfbdea1 /dot_vim/indent/indent-r.vim
parentfix pager again (diff)
many more renames
Diffstat (limited to 'dot_vim/indent/indent-r.vim')
-rw-r--r--dot_vim/indent/indent-r.vim50
1 files changed, 50 insertions, 0 deletions
diff --git a/dot_vim/indent/indent-r.vim b/dot_vim/indent/indent-r.vim
new file mode 100644
index 0000000..30c03c5
--- /dev/null
+++ b/dot_vim/indent/indent-r.vim
@@ -0,0 +1,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: