comparison runtime/indent/rmd.vim @ 24520:5bda4653aced

Update runtime files Commit: https://github.com/vim/vim/commit/11e3c5ba820325b69cb56f70e13c21d7b8808d33 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Apr 21 18:09:37 2021 +0200 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Apr 2021 18:15:04 +0200
parents 1eaf34420bb3
children b2412874362f
comparison
equal deleted inserted replaced
24519:da748a66a65a 24520:5bda4653aced
1 " Vim indent file 1 " Vim indent file
2 " Language: Rmd 2 " Language: Rmd
3 " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> 3 " Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
4 " Homepage: https://github.com/jalvesaq/R-Vim-runtime 4 " Homepage: https://github.com/jalvesaq/R-Vim-runtime
5 " Last Change: Sun Aug 19, 2018 09:14PM 5 " Last Change: Sun Mar 28, 2021 08:05PM
6 6
7 7
8 " Only load this indent file when no other was loaded. 8 " Only load this indent file when no other was loaded.
9 if exists("b:did_indent") 9 if exists("b:did_indent")
10 finish 10 finish
11 endif 11 endif
12 runtime indent/r.vim 12 runtime indent/r.vim
13 let s:RIndent = function(substitute(&indentexpr, "()", "", "")) 13 let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
14 let b:did_indent = 1 14 let b:did_indent = 1
15 15
16 setlocal indentkeys=0{,0},:,!^F,o,O,e 16 setlocal indentkeys=0{,0},<:>,!^F,o,O,e
17 setlocal indentexpr=GetRmdIndent() 17 setlocal indentexpr=GetRmdIndent()
18 18
19 if exists("*GetRmdIndent") 19 if exists("*GetRmdIndent")
20 finish 20 finish
21 endif 21 endif
22 22
23 let s:cpo_save = &cpo 23 let s:cpo_save = &cpo
24 set cpo&vim 24 set cpo&vim
25
26 " Simple Python indentation algorithm
27 function s:GetPyIndent()
28 let plnum = prevnonblank(v:lnum - 1)
29 let pline = getline(plnum)
30 let cline = getline(v:lnum)
31 if pline =~ '^s```\s*{\s*python '
32 return 0
33 elseif pline =~ ':$'
34 return indent(plnum) + &shiftwidth
35 elseif cline =~ 'else:$'
36 return indent(plnum) - &shiftwidth
37 endif
38 return indent(plnum)
39 endfunction
25 40
26 function s:GetMdIndent() 41 function s:GetMdIndent()
27 let pline = getline(v:lnum - 1) 42 let pline = getline(v:lnum - 1)
28 let cline = getline(v:lnum) 43 let cline = getline(v:lnum)
29 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' 44 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
35 endif 50 endif
36 return indent(prevnonblank(v:lnum - 1)) 51 return indent(prevnonblank(v:lnum - 1))
37 endfunction 52 endfunction
38 53
39 function s:GetYamlIndent() 54 function s:GetYamlIndent()
40 let pline = getline(v:lnum - 1) 55 let plnum = prevnonblank(v:lnum - 1)
56 let pline = getline(plnum)
41 if pline =~ ':\s*$' 57 if pline =~ ':\s*$'
42 return indent(v:lnum) + shiftwidth() 58 return indent(plnum) + shiftwidth()
43 elseif pline =~ '^\s*- ' 59 elseif pline =~ '^\s*- '
44 return indent(v:lnum) + 2 60 return indent(v:lnum) + 2
45 endif 61 endif
46 return indent(prevnonblank(v:lnum - 1)) 62 return indent(plnum)
47 endfunction 63 endfunction
48 64
49 function GetRmdIndent() 65 function GetRmdIndent()
50 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' 66 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
51 return 0 67 return 0
52 endif 68 endif
53 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") 69 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
54 return s:RIndent() 70 return s:RIndent()
55 elseif v:lnum > 1 && search('^---$', "bnW") == 1 && 71 elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
56 \ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum) 72 \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
57 return s:GetYamlIndent() 73 return s:GetYamlIndent()
74 elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
75 return s:GetPyIndent()
58 else 76 else
59 return s:GetMdIndent() 77 return s:GetMdIndent()
60 endif 78 endif
61 endfunction 79 endfunction
62 80