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
|
2021-05-02 09:45:09 -07:00
|
|
|
" Last Change: Sun Mar 28, 2021 08:05PM
|
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
|
|
|
|
|
2021-05-02 09:45:09 -07:00
|
|
|
setlocal indentkeys=0{,0},<:>,!^F,o,O,e
|
2014-07-10 21:05:51 -07:00
|
|
|
setlocal indentexpr=GetRmdIndent()
|
|
|
|
|
|
|
|
if exists("*GetRmdIndent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2021-05-02 09:45:09 -07:00
|
|
|
" Simple Python indentation algorithm
|
|
|
|
function s:GetPyIndent()
|
|
|
|
let plnum = prevnonblank(v:lnum - 1)
|
|
|
|
let pline = getline(plnum)
|
|
|
|
let cline = getline(v:lnum)
|
|
|
|
if pline =~ '^s```\s*{\s*python '
|
|
|
|
return 0
|
|
|
|
elseif pline =~ ':$'
|
|
|
|
return indent(plnum) + &shiftwidth
|
|
|
|
elseif cline =~ 'else:$'
|
|
|
|
return indent(plnum) - &shiftwidth
|
|
|
|
endif
|
|
|
|
return indent(plnum)
|
|
|
|
endfunction
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
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()
|
2021-05-02 09:45:09 -07:00
|
|
|
let plnum = prevnonblank(v:lnum - 1)
|
|
|
|
let pline = getline(plnum)
|
2018-10-29 15:38:41 -07:00
|
|
|
if pline =~ ':\s*$'
|
2021-05-02 09:45:09 -07:00
|
|
|
return indent(plnum) + shiftwidth()
|
2018-10-29 15:38:41 -07:00
|
|
|
elseif pline =~ '^\s*- '
|
|
|
|
return indent(v:lnum) + 2
|
|
|
|
endif
|
2021-05-02 09:45:09 -07:00
|
|
|
return indent(plnum)
|
2018-10-29 15:38:41 -07:00
|
|
|
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()
|
2021-05-02 09:45:09 -07:00
|
|
|
elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
|
|
|
|
\ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
|
2018-10-29 15:38:41 -07:00
|
|
|
return s:GetYamlIndent()
|
2021-05-02 09:45:09 -07:00
|
|
|
elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
|
|
|
|
return s:GetPyIndent()
|
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
|