Mercurial > vim
annotate runtime/indent/rhelp.vim @ 22936:00b0275ffe7f v8.2.2015
patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Commit: https://github.com/vim/vim/commit/2bede173a177e227e6224a8713f5b88a38d011af
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 19 18:53:18 2020 +0100
patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Problem: Vim9: literal dict #{} is not like any other language.
Solution: Support the JavaScript syntax.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 19 Nov 2020 19:00:06 +0100 |
parents | 4aae8146c21f |
children | b2412874362f |
rev | line source |
---|---|
6051 | 1 " Vim indent file |
2 " Language: R Documentation (Help), *.Rd | |
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 |
da01d5da2cfa
commit https://github.com/vim/vim/commit/77cdfd10382e01cc51f4ba1a9177032351843151
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
5 " Last Change: Tue Apr 07, 2015 04:38PM |
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 noautoindent | |
17 setlocal nocindent | |
18 setlocal nosmartindent | |
19 setlocal nolisp | |
20 setlocal indentkeys=0{,0},:,!^F,o,O,e | |
21 setlocal indentexpr=GetCorrectRHelpIndent() | |
22 | |
6840 | 23 " Only define the functions once. |
24 if exists("*GetRHelpIndent") | |
25 finish | |
26 endif | |
27 | |
6051 | 28 function s:SanitizeRHelpLine(line) |
29 let newline = substitute(a:line, '\\\\', "x", "g") | |
30 let newline = substitute(newline, '\\{', "x", "g") | |
31 let newline = substitute(newline, '\\}', "x", "g") | |
32 let newline = substitute(newline, '\\%', "x", "g") | |
33 let newline = substitute(newline, '%.*', "", "") | |
34 let newline = substitute(newline, '\s*$', "", "") | |
35 return newline | |
36 endfunction | |
37 | |
38 function GetRHelpIndent() | |
39 | |
40 let clnum = line(".") " current line | |
41 if clnum == 1 | |
42 return 0 | |
43 endif | |
44 let cline = getline(clnum) | |
45 | |
46 if cline =~ '^\s*}\s*$' | |
47 let i = clnum | |
48 let bb = -1 | |
49 while bb != 0 && i > 1 | |
50 let i -= 1 | |
51 let line = s:SanitizeRHelpLine(getline(i)) | |
52 let line2 = substitute(line, "{", "", "g") | |
53 let openb = strlen(line) - strlen(line2) | |
54 let line3 = substitute(line2, "}", "", "g") | |
55 let closeb = strlen(line2) - strlen(line3) | |
56 let bb += openb - closeb | |
57 endwhile | |
58 return indent(i) | |
59 endif | |
60 | |
61 if cline =~ '^\s*#ifdef\>' || cline =~ '^\s*#endif\>' | |
62 return 0 | |
63 endif | |
64 | |
65 let lnum = clnum - 1 | |
66 let line = getline(lnum) | |
67 if line =~ '^\s*#ifdef\>' || line =~ '^\s*#endif\>' | |
68 let lnum -= 1 | |
69 let line = getline(lnum) | |
70 endif | |
71 while lnum > 1 && (line =~ '^\s*$' || line =~ '^#ifdef' || line =~ '^#endif') | |
72 let lnum -= 1 | |
73 let line = getline(lnum) | |
74 endwhile | |
75 if lnum == 1 | |
76 return 0 | |
77 endif | |
78 let line = s:SanitizeRHelpLine(line) | |
79 let line2 = substitute(line, "{", "", "g") | |
80 let openb = strlen(line) - strlen(line2) | |
81 let line3 = substitute(line2, "}", "", "g") | |
82 let closeb = strlen(line2) - strlen(line3) | |
83 let bb = openb - closeb | |
84 | |
11347 | 85 let ind = indent(lnum) + (bb * shiftwidth()) |
6051 | 86 |
87 if line =~ '^\s*}\s*$' | |
88 let ind = indent(lnum) | |
89 endif | |
90 | |
91 if ind < 0 | |
92 return 0 | |
93 endif | |
94 | |
95 return ind | |
96 endfunction | |
97 | |
98 function GetCorrectRHelpIndent() | |
99 let lastsection = search('^\\[a-z]*{', "bncW") | |
100 let secname = getline(lastsection) | |
101 if secname =~ '^\\usage{' || secname =~ '^\\examples{' || secname =~ '^\\dontshow{' || secname =~ '^\\dontrun{' || secname =~ '^\\donttest{' || secname =~ '^\\testonly{' || secname =~ '^\\method{.*}{.*}(' | |
102 return s:RIndent() | |
103 else | |
104 return GetRHelpIndent() | |
105 endif | |
106 endfunction | |
107 | |
108 " vim: sw=2 |