diff options
Diffstat (limited to 'runtime/indent/rmd.vim')
-rw-r--r-- | runtime/indent/rmd.vim | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/runtime/indent/rmd.vim b/runtime/indent/rmd.vim index 88904405e..182b07cba 100644 --- a/runtime/indent/rmd.vim +++ b/runtime/indent/rmd.vim @@ -2,7 +2,7 @@ " Language: Rmd " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> " Homepage: https://github.com/jalvesaq/R-Vim-runtime -" Last Change: Tue Apr 07, 2015 04:38PM +" Last Change: Sun Aug 19, 2018 09:14PM " Only load this indent file when no other was loaded. @@ -20,7 +20,10 @@ if exists("*GetRmdIndent") finish endif -function GetMdIndent() +let s:cpo_save = &cpo +set cpo&vim + +function s:GetMdIndent() 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\+' @@ -33,15 +36,31 @@ function GetMdIndent() return indent(prevnonblank(v:lnum - 1)) endfunction +function s:GetYamlIndent() + let pline = getline(v:lnum - 1) + if pline =~ ':\s*$' + return indent(v:lnum) + &sw + elseif pline =~ '^\s*- ' + return indent(v:lnum) + 2 + endif + return indent(prevnonblank(v:lnum - 1)) +endfunction + function GetRmdIndent() if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' return 0 endif if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") return s:RIndent() + elseif v:lnum > 1 && search('^---$', "bnW") == 1 && + \ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum) + return s:GetYamlIndent() else - return GetMdIndent() + return s:GetMdIndent() endif endfunction +let &cpo = s:cpo_save +unlet s:cpo_save + " vim: sw=2 |