Mercurial > vim
annotate runtime/indent/rmd.vim @ 27392:ec2ba9acec1b v8.2.4224
patch 8.2.4224: Vim9: no error when using a number for map() second argument
Commit: https://github.com/vim/vim/commit/1080c48ec8d672d7e9fbefb5a1255c9df09a2884
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 26 18:26:21 2022 +0000
patch 8.2.4224: Vim9: no error when using a number for map() second argument
Problem: Vim9: no error when using a number for map() second argument
Solution: Disallow number to string conversion. (closes https://github.com/vim/vim/issues/9630)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 26 Jan 2022 19:30:03 +0100 |
parents | 5bda4653aced |
children | b2412874362f |
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 |
24520 | 5 " Last Change: Sun Mar 28, 2021 08:05PM |
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 | |
24520 | 16 setlocal indentkeys=0{,0},<:>,!^F,o,O,e |
6051 | 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 | |
24520 | 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 | |
40 | |
14637 | 41 function s:GetMdIndent() |
6051 | 42 let pline = getline(v:lnum - 1) |
43 let cline = getline(v:lnum) | |
44 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' | |
45 return indent(v:lnum) | |
46 elseif pline =~ '^\s*[-\+\*]\s' | |
47 return indent(v:lnum - 1) + 2 | |
48 elseif pline =~ '^\s*\d\+\.\s\+' | |
49 return indent(v:lnum - 1) + 3 | |
50 endif | |
51 return indent(prevnonblank(v:lnum - 1)) | |
52 endfunction | |
53 | |
14637 | 54 function s:GetYamlIndent() |
24520 | 55 let plnum = prevnonblank(v:lnum - 1) |
56 let pline = getline(plnum) | |
14637 | 57 if pline =~ ':\s*$' |
24520 | 58 return indent(plnum) + shiftwidth() |
14637 | 59 elseif pline =~ '^\s*- ' |
60 return indent(v:lnum) + 2 | |
61 endif | |
24520 | 62 return indent(plnum) |
14637 | 63 endfunction |
64 | |
6051 | 65 function GetRmdIndent() |
6840 | 66 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' |
6051 | 67 return 0 |
68 endif | |
6840 | 69 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") |
6051 | 70 return s:RIndent() |
24520 | 71 elseif v:lnum > 1 && (search('^---$', "bnW") == 1 && |
72 \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum)) | |
14637 | 73 return s:GetYamlIndent() |
24520 | 74 elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW") |
75 return s:GetPyIndent() | |
6051 | 76 else |
14637 | 77 return s:GetMdIndent() |
6051 | 78 endif |
79 endfunction | |
80 | |
14637 | 81 let &cpo = s:cpo_save |
82 unlet s:cpo_save | |
83 | |
6051 | 84 " vim: sw=2 |