0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
vim/runtime/indent/rmd.vim

67 lines
1.6 KiB
VimL
Raw Normal View History

2014-07-10 22:01:47 +02:00
" Vim indent file
" Language: Rmd
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
2016-03-12 12:57:59 +01:00
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
2018-08-28 22:58:02 +02:00
" Last Change: Sun Aug 19, 2018 09:14PM
2014-07-10 22:01:47 +02: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-08-28 22:58:02 +02:00
let s:cpo_save = &cpo
set cpo&vim
function s:GetMdIndent()
2014-07-10 22:01:47 +02: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-08-28 22:58:02 +02:00
function s:GetYamlIndent()
let pline = getline(v:lnum - 1)
if pline =~ ':\s*$'
2019-05-09 19:16:22 +02:00
return indent(v:lnum) + shiftwidth()
2018-08-28 22:58:02 +02:00
elseif pline =~ '^\s*- '
return indent(v:lnum) + 2
endif
return indent(prevnonblank(v:lnum - 1))
endfunction
2014-07-10 22:01:47 +02:00
function GetRmdIndent()
2015-06-19 13:27:23 +02:00
if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
2014-07-10 22:01:47 +02:00
return 0
endif
2015-06-19 13:27:23 +02:00
if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
2014-07-10 22:01:47 +02:00
return s:RIndent()
2018-08-28 22:58:02 +02:00
elseif v:lnum > 1 && search('^---$', "bnW") == 1 &&
\ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum)
return s:GetYamlIndent()
2014-07-10 22:01:47 +02:00
else
2018-08-28 22:58:02 +02:00
return s:GetMdIndent()
2014-07-10 22:01:47 +02:00
endif
endfunction
2018-08-28 22:58:02 +02:00
let &cpo = s:cpo_save
unlet s:cpo_save
2014-07-10 22:01:47 +02:00
" vim: sw=2