annotate runtime/indent/rmd.vim @ 29466:d5b1a7cece0a

Added tag v9.0.0074 for changeset 1ae3e2d691a0e3782ca40c32a88a27be21bdbcc3
author Bram Moolenaar <Bram@vim.org>
date Tue, 26 Jul 2022 12:30:06 +0200
parents 5bda4653aced
children b2412874362f
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
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
5 " Last Change: Sun Mar 28, 2021 08:05PM
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
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
16 setlocal indentkeys=0{,0},<:>,!^F,o,O,e
6051
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
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
26 " Simple Python indentation algorithm
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
27 function s:GetPyIndent()
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
28 let plnum = prevnonblank(v:lnum - 1)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
29 let pline = getline(plnum)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
30 let cline = getline(v:lnum)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
31 if pline =~ '^s```\s*{\s*python '
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
32 return 0
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
33 elseif pline =~ ':$'
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
34 return indent(plnum) + &shiftwidth
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
35 elseif cline =~ 'else:$'
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
36 return indent(plnum) - &shiftwidth
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
37 endif
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
38 return indent(plnum)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
39 endfunction
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
40
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
41 function s:GetMdIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 let pline = getline(v:lnum - 1)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 let cline = getline(v:lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 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
45 return indent(v:lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 elseif pline =~ '^\s*[-\+\*]\s'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 return indent(v:lnum - 1) + 2
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 elseif pline =~ '^\s*\d\+\.\s\+'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 return indent(v:lnum - 1) + 3
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 return indent(prevnonblank(v:lnum - 1))
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
54 function s:GetYamlIndent()
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
55 let plnum = prevnonblank(v:lnum - 1)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
56 let pline = getline(plnum)
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
57 if pline =~ ':\s*$'
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
58 return indent(plnum) + shiftwidth()
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
59 elseif pline =~ '^\s*- '
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
60 return indent(v:lnum) + 2
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
61 endif
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
62 return indent(plnum)
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
63 endfunction
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
64
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 function GetRmdIndent()
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
66 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
69 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 return s:RIndent()
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
71 elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
72 \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
73 return s:GetYamlIndent()
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
74 elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
75 return s:GetPyIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 else
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
77 return s:GetMdIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
81 let &cpo = s:cpo_save
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
82 unlet s:cpo_save
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
83
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 " vim: sw=2