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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: Rmd
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
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
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
5 " Last Change: Sun Aug 19, 2018 09:14PM
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 " Only load this indent file when no other was loaded.
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 if exists("b:did_indent")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 finish
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 runtime indent/r.vim
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 let b:did_indent = 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 setlocal indentkeys=0{,0},:,!^F,o,O,e
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 setlocal indentexpr=GetRmdIndent()
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 if exists("*GetRmdIndent")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 finish
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
23 let s:cpo_save = &cpo
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
24 set cpo&vim
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
25
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
26 function s:GetMdIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 let pline = getline(v:lnum - 1)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 let cline = getline(v:lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 return indent(v:lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 elseif pline =~ '^\s*[-\+\*]\s'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 return indent(v:lnum - 1) + 2
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 elseif pline =~ '^\s*\d\+\.\s\+'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 return indent(v:lnum - 1) + 3
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 return indent(prevnonblank(v:lnum - 1))
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
39 function s:GetYamlIndent()
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
40 let pline = getline(v:lnum - 1)
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
41 if pline =~ ':\s*$'
16610
1eaf34420bb3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14637
diff changeset
42 return indent(v:lnum) + shiftwidth()
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
43 elseif pline =~ '^\s*- '
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
44 return indent(v:lnum) + 2
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
45 endif
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
46 return indent(prevnonblank(v:lnum - 1))
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
47 endfunction
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
48
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 function GetRmdIndent()
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
50 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
53 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 return s:RIndent()
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
55 elseif v:lnum > 1 && search('^---$', "bnW") == 1 &&
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
56 \ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum)
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
57 return s:GetYamlIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 else
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
59 return s:GetMdIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
63 let &cpo = s:cpo_save
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
64 unlet s:cpo_save
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
65
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 " vim: sw=2