xref: /vim-8.2.3635/runtime/indent/rmd.vim (revision 12ee7ff0)
1" Vim indent file
2" Language:	Rmd
3" Author:	Jakson Alves de Aquino <[email protected]>
4" Homepage:     https://github.com/jalvesaq/R-Vim-runtime
5" Last Change:	Sun Aug 19, 2018  09:14PM
6
7
8" Only load this indent file when no other was loaded.
9if exists("b:did_indent")
10  finish
11endif
12runtime indent/r.vim
13let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
14let b:did_indent = 1
15
16setlocal indentkeys=0{,0},:,!^F,o,O,e
17setlocal indentexpr=GetRmdIndent()
18
19if exists("*GetRmdIndent")
20  finish
21endif
22
23let s:cpo_save = &cpo
24set cpo&vim
25
26function s:GetMdIndent()
27  let pline = getline(v:lnum - 1)
28  let cline = getline(v:lnum)
29  if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
30    return indent(v:lnum)
31  elseif pline =~ '^\s*[-\+\*]\s'
32    return indent(v:lnum - 1) + 2
33  elseif pline =~ '^\s*\d\+\.\s\+'
34    return indent(v:lnum - 1) + 3
35  endif
36  return indent(prevnonblank(v:lnum - 1))
37endfunction
38
39function s:GetYamlIndent()
40  let pline = getline(v:lnum - 1)
41  if pline =~ ':\s*$'
42    return indent(v:lnum) + shiftwidth()
43  elseif pline =~ '^\s*- '
44    return indent(v:lnum) + 2
45  endif
46  return indent(prevnonblank(v:lnum - 1))
47endfunction
48
49function GetRmdIndent()
50  if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
51    return 0
52  endif
53  if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
54    return s:RIndent()
55  elseif v:lnum > 1 && search('^---$', "bnW") == 1 &&
56        \ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum)
57    return s:GetYamlIndent()
58  else
59    return s:GetMdIndent()
60  endif
61endfunction
62
63let &cpo = s:cpo_save
64unlet s:cpo_save
65
66" vim: sw=2
67