2014-07-10 21:05:51 -07:00
|
|
|
" Vim indent file
|
|
|
|
" Language: Rmd
|
|
|
|
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
|
2016-06-20 07:37:19 -07:00
|
|
|
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
|
2018-10-29 15:38:41 -07:00
|
|
|
" Last Change: Sun Aug 19, 2018 09:14PM
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
" Only load this indent file when no other was loaded.
|
|
|
|
if exists("b:did_indent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
runtime indent/r.vim
|
|
|
|
let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
|
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal indentkeys=0{,0},:,!^F,o,O,e
|
|
|
|
setlocal indentexpr=GetRmdIndent()
|
|
|
|
|
|
|
|
if exists("*GetRmdIndent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
function s:GetMdIndent()
|
2014-07-10 21:05:51 -07:00
|
|
|
let pline = getline(v:lnum - 1)
|
|
|
|
let cline = getline(v:lnum)
|
|
|
|
if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
|
|
|
|
return indent(v:lnum)
|
|
|
|
elseif pline =~ '^\s*[-\+\*]\s'
|
|
|
|
return indent(v:lnum - 1) + 2
|
|
|
|
elseif pline =~ '^\s*\d\+\.\s\+'
|
|
|
|
return indent(v:lnum - 1) + 3
|
|
|
|
endif
|
|
|
|
return indent(prevnonblank(v:lnum - 1))
|
|
|
|
endfunction
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
function s:GetYamlIndent()
|
|
|
|
let pline = getline(v:lnum - 1)
|
|
|
|
if pline =~ ':\s*$'
|
2019-08-01 14:21:22 -07:00
|
|
|
return indent(v:lnum) + shiftwidth()
|
2018-10-29 15:38:41 -07:00
|
|
|
elseif pline =~ '^\s*- '
|
|
|
|
return indent(v:lnum) + 2
|
|
|
|
endif
|
|
|
|
return indent(prevnonblank(v:lnum - 1))
|
|
|
|
endfunction
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
function GetRmdIndent()
|
2015-04-03 07:44:18 -07:00
|
|
|
if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
|
2014-07-10 21:05:51 -07:00
|
|
|
return 0
|
|
|
|
endif
|
2015-04-03 07:44:18 -07:00
|
|
|
if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
|
2014-07-10 21:05:51 -07:00
|
|
|
return s:RIndent()
|
2018-10-29 15:38:41 -07:00
|
|
|
elseif v:lnum > 1 && search('^---$', "bnW") == 1 &&
|
|
|
|
\ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum)
|
|
|
|
return s:GetYamlIndent()
|
2014-07-10 21:05:51 -07:00
|
|
|
else
|
2018-10-29 15:38:41 -07:00
|
|
|
return s:GetMdIndent()
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" vim: sw=2
|