Mercurial > vim
annotate runtime/indent/rmd.vim @ 16935:60e55f8239ed
Added tag v8.1.1468 for changeset 87abfb36d81583386a29a2ec59ff8ef6d84f5dc6
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 05 Jun 2019 21:30:08 +0200 |
parents | 1eaf34420bb3 |
children | 5bda4653aced |
rev | line source |
---|---|
6051 | 1 " Vim indent file |
2 " Language: Rmd | |
3 " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> | |
8497
da01d5da2cfa
commit https://github.com/vim/vim/commit/77cdfd10382e01cc51f4ba1a9177032351843151
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
4 " Homepage: https://github.com/jalvesaq/R-Vim-runtime |
14637 | 5 " Last Change: Sun Aug 19, 2018 09:14PM |
6051 | 6 |
7 | |
8 " Only load this indent file when no other was loaded. | |
9 if exists("b:did_indent") | |
10 finish | |
11 endif | |
12 runtime indent/r.vim | |
13 let s:RIndent = function(substitute(&indentexpr, "()", "", "")) | |
14 let b:did_indent = 1 | |
15 | |
16 setlocal indentkeys=0{,0},:,!^F,o,O,e | |
17 setlocal indentexpr=GetRmdIndent() | |
18 | |
19 if exists("*GetRmdIndent") | |
20 finish | |
21 endif | |
22 | |
14637 | 23 let s:cpo_save = &cpo |
24 set cpo&vim | |
25 | |
26 function s:GetMdIndent() | |
6051 | 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)) | |
37 endfunction | |
38 | |
14637 | 39 function s:GetYamlIndent() |
40 let pline = getline(v:lnum - 1) | |
41 if pline =~ ':\s*$' | |
16610 | 42 return indent(v:lnum) + shiftwidth() |
14637 | 43 elseif pline =~ '^\s*- ' |
44 return indent(v:lnum) + 2 | |
45 endif | |
46 return indent(prevnonblank(v:lnum - 1)) | |
47 endfunction | |
48 | |
6051 | 49 function GetRmdIndent() |
6840 | 50 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' |
6051 | 51 return 0 |
52 endif | |
6840 | 53 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") |
6051 | 54 return s:RIndent() |
14637 | 55 elseif v:lnum > 1 && search('^---$', "bnW") == 1 && |
56 \ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum) | |
57 return s:GetYamlIndent() | |
6051 | 58 else |
14637 | 59 return s:GetMdIndent() |
6051 | 60 endif |
61 endfunction | |
62 | |
14637 | 63 let &cpo = s:cpo_save |
64 unlet s:cpo_save | |
65 | |
6051 | 66 " vim: sw=2 |