Mercurial > vim
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 |
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 |
32061 | 5 " Last Change: Wed Nov 09, 2022 09:44PM |
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 | |
32061 | 19 let b:undo_indent = "setl inde< indk<" |
20 | |
6051 | 21 if exists("*GetRmdIndent") |
22 finish | |
23 endif | |
24 | |
14637 | 25 let s:cpo_save = &cpo |
26 set cpo&vim | |
27 | |
24520 | 28 " Simple Python indentation algorithm |
29 function s:GetPyIndent() | |
30 let plnum = prevnonblank(v:lnum - 1) | |
31 let pline = getline(plnum) | |
32 let cline = getline(v:lnum) | |
33 if pline =~ '^s```\s*{\s*python ' | |
34 return 0 | |
35 elseif pline =~ ':$' | |
36 return indent(plnum) + &shiftwidth | |
37 elseif cline =~ 'else:$' | |
38 return indent(plnum) - &shiftwidth | |
39 endif | |
40 return indent(plnum) | |
41 endfunction | |
42 | |
14637 | 43 function s:GetMdIndent() |
6051 | 44 let pline = getline(v:lnum - 1) |
45 let cline = getline(v:lnum) | |
46 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' | |
47 return indent(v:lnum) | |
48 elseif pline =~ '^\s*[-\+\*]\s' | |
49 return indent(v:lnum - 1) + 2 | |
50 elseif pline =~ '^\s*\d\+\.\s\+' | |
51 return indent(v:lnum - 1) + 3 | |
32061 | 52 elseif pline =~ '^\[\^\S\+\]: ' |
53 return indent(v:lnum - 1) + shiftwidth() | |
6051 | 54 endif |
55 return indent(prevnonblank(v:lnum - 1)) | |
56 endfunction | |
57 | |
14637 | 58 function s:GetYamlIndent() |
24520 | 59 let plnum = prevnonblank(v:lnum - 1) |
60 let pline = getline(plnum) | |
14637 | 61 if pline =~ ':\s*$' |
24520 | 62 return indent(plnum) + shiftwidth() |
14637 | 63 elseif pline =~ '^\s*- ' |
64 return indent(v:lnum) + 2 | |
65 endif | |
24520 | 66 return indent(plnum) |
14637 | 67 endfunction |
68 | |
6051 | 69 function GetRmdIndent() |
6840 | 70 if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' |
6051 | 71 return 0 |
72 endif | |
6840 | 73 if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") |
6051 | 74 return s:RIndent() |
24520 | 75 elseif v:lnum > 1 && (search('^---$', "bnW") == 1 && |
76 \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum)) | |
14637 | 77 return s:GetYamlIndent() |
24520 | 78 elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW") |
79 return s:GetPyIndent() | |
6051 | 80 else |
14637 | 81 return s:GetMdIndent() |
6051 | 82 endif |
83 endfunction | |
84 | |
14637 | 85 let &cpo = s:cpo_save |
86 unlet s:cpo_save | |
87 | |
6051 | 88 " vim: sw=2 |