annotate runtime/indent/mma.vim @ 21303:7c50dfe302f8 v8.2.1202

patch 8.2.1202: Vim9: crash when calling a closure from a builtin function Commit: https://github.com/vim/vim/commit/08f7a41b0a280e5901eb4ee4bbfe682113863492 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 13 20:41:08 2020 +0200 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function Problem: Vim9: crash when calling a closure from a builtin function. Solution: Use the current execution context. (closes https://github.com/vim/vim/issues/6441)
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Jul 2020 20:45:04 +0200
parents 1eaf34420bb3
children 9c221ad9634a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
1 " Vim indent file
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
2 " Language: Mathematica
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
3 " Author: steve layland <layland@wolfram.com>
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
4 " Last Change: Sat May 10 18:56:22 CDT 2005
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
5 " Source: http://vim.sourceforge.net/scripts/script.php?script_id=1274
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
6 " http://members.wolfram.com/layland/vim/indent/mma.vim
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
7 "
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
8 " NOTE:
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
9 " Empty .m files will automatically be presumed to be Matlab files
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
10 " unless you have the following in your .vimrc:
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
11 "
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
12 " let filetype_m="mma"
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
13 "
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
14 " Credits:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
15 " o steve hacked this out of a random indent file in the Vim 6.1
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
16 " distribution that he no longer remembers...sh.vim? Thanks!
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
17
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
18 " Only load this indent file when no other was loaded.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
19 if exists("b:did_indent")
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
20 finish
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
21 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
22 let b:did_indent = 1
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
23
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
24 setlocal indentexpr=GetMmaIndent()
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
25 setlocal indentkeys+=0[,0],0(,0)
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
26 setlocal nosi "turn off smart indent so we don't over analyze } blocks
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
27
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
28 if exists("*GetMmaIndent")
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
29 finish
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
30 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
31
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
32 function GetMmaIndent()
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
33
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
34 " Hit the start of the file, use zero indent.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
35 if v:lnum == 0
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
36 return 0
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
37 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
38
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
39 " Find a non-blank line above the current line.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
40 let lnum = prevnonblank(v:lnum - 1)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
41
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
42 " use indenting as a base
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
43 let ind = indent(v:lnum)
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
44 let lnum = v:lnum
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
45
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
46 " if previous line has an unmatched bracket, or ( indent.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
47 " doesn't do multiple parens/blocks/etc...
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
48
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
49 " also, indent only if this line if this line isn't starting a new
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
50 " block... TODO - fix this with indentkeys?
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
51 if getline(v:lnum-1) =~ '\\\@<!\%(\[[^\]]*\|([^)]*\|{[^}]*\)$' && getline(v:lnum) !~ '\s\+[\[({]'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 856
diff changeset
52 let ind = ind+shiftwidth()
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
53 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
54
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
55 " if this line had unmatched closing block,
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
56 " indent to the matching opening block
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
57 if getline(v:lnum) =~ '[^[]*]\s*$'
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
58 " move to the closing bracket
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
59 call search(']','bW')
16610
1eaf34420bb3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
60 " and find its partner's indent
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
61 let ind = indent(searchpair('\[','',']','bWn'))
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
62 " same for ( blocks
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
63 elseif getline(v:lnum) =~ '[^(]*)$'
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
64 call search(')','bW')
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
65 let ind = indent(searchpair('(','',')','bWn'))
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
66
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
67 " and finally, close { blocks if si ain't already set
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
68 elseif getline(v:lnum) =~ '[^{]*}'
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
69 call search('}','bW')
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
70 let ind = indent(searchpair('{','','}','bWn'))
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
71 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
72
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
73 return ind
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
74 endfunction
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
75