annotate runtime/indent/rmd.vim @ 33295:a43861545866 v9.0.1913

patch 9.0.1913: if_python: undefined behaviour for function pointers Commit: https://github.com/vim/vim/commit/2ce070c27acd12ccc614afa4cecf4970a645a4af Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Tue Sep 19 20:30:22 2023 +0200 patch 9.0.1913: if_python: undefined behaviour for function pointers Problem: if_python: undefined behaviour for function pointers Solution: Fix if_python undefined behavior for function pointer casts Identified by clang 17 UBSAN (see #12745). Make sure to cast function pointers with the same signature only. closes: #13122 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Tue, 19 Sep 2023 20:45:05 +0200
parents b2412874362f
children 02bd0fe77c68
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
32061
b2412874362f Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24520
diff changeset
5 " Last Change: Wed Nov 09, 2022 09:44PM
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
32061
b2412874362f Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24520
diff changeset
19 let b:undo_indent = "setl inde< indk<"
b2412874362f Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24520
diff changeset
20
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 if exists("*GetRmdIndent")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 finish
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
25 let s:cpo_save = &cpo
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
26 set cpo&vim
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
27
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
28 " Simple Python indentation algorithm
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
29 function s:GetPyIndent()
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
30 let plnum = prevnonblank(v:lnum - 1)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
31 let pline = getline(plnum)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
32 let cline = getline(v:lnum)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
33 if pline =~ '^s```\s*{\s*python '
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
34 return 0
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
35 elseif pline =~ ':$'
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 elseif cline =~ 'else:$'
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
38 return indent(plnum) - &shiftwidth
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
39 endif
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
40 return indent(plnum)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
41 endfunction
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
42
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
43 function s:GetMdIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 let pline = getline(v:lnum - 1)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 let cline = getline(v:lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 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
47 return indent(v:lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 elseif pline =~ '^\s*[-\+\*]\s'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 return indent(v:lnum - 1) + 2
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 elseif pline =~ '^\s*\d\+\.\s\+'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 return indent(v:lnum - 1) + 3
32061
b2412874362f Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24520
diff changeset
52 elseif pline =~ '^\[\^\S\+\]: '
b2412874362f Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24520
diff changeset
53 return indent(v:lnum - 1) + shiftwidth()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 return indent(prevnonblank(v:lnum - 1))
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
58 function s:GetYamlIndent()
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
59 let plnum = prevnonblank(v:lnum - 1)
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
60 let pline = getline(plnum)
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
61 if pline =~ ':\s*$'
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
62 return indent(plnum) + shiftwidth()
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
63 elseif pline =~ '^\s*- '
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
64 return indent(v:lnum) + 2
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
65 endif
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
66 return indent(plnum)
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
67 endfunction
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
68
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 function GetRmdIndent()
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
70 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
73 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 return s:RIndent()
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
75 elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
76 \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
77 return s:GetYamlIndent()
24520
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
78 elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
5bda4653aced Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
79 return s:GetPyIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 else
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
81 return s:GetMdIndent()
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
85 let &cpo = s:cpo_save
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
86 unlet s:cpo_save
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 8497
diff changeset
87
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 " vim: sw=2