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

85 lines
2.1 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
2021-04-21 18:09:37 +02:00
" Last Change: Sun Mar 28, 2021 08:05PM
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
2021-04-21 18:09:37 +02:00
setlocal indentkeys=0{,0},<:>,!^F,o,O,e
2014-07-10 22:01:47 +02:00
setlocal indentexpr=GetRmdIndent()
if exists("*GetRmdIndent")
finish
endif
2018-08-28 22:58:02 +02:00
let s:cpo_save = &cpo
set cpo&vim
2021-04-21 18:09:37 +02: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-08-28 22:58:02 +02:00
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()
2021-04-21 18:09:37 +02:00
let plnum = prevnonblank(v:lnum - 1)
let pline = getline(plnum)
2018-08-28 22:58:02 +02:00
if pline =~ ':\s*$'
2021-04-21 18:09:37 +02:00
return indent(plnum) + shiftwidth()
2018-08-28 22:58:02 +02:00
elseif pline =~ '^\s*- '
return indent(v:lnum) + 2
endif
2021-04-21 18:09:37 +02:00
return indent(plnum)
2018-08-28 22:58:02 +02:00
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()
2021-04-21 18:09:37 +02:00
elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
\ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
2018-08-28 22:58:02 +02:00
return s:GetYamlIndent()
2021-04-21 18:09:37 +02:00
elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
return s:GetPyIndent()
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