annotate runtime/indent/mma.vim @ 31184:6b218e595d9f v9.0.0926

patch 9.0.0926: Coverity warns for not using return value of dict_add() Commit: https://github.com/vim/vim/commit/bc222152d8dea252aa5f1fa24b5536ed269feb92 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Nov 23 11:34:01 2022 +0000 patch 9.0.0926: Coverity warns for not using return value of dict_add() Problem: Coverity warns for not using return value of dict_add(). Solution: When dict_add() fails then don't call hash_remove().
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Nov 2022 12:45:04 +0100
parents 6dd88e45d47d
children
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
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
2 " Language: Mathematica
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
3 " Maintainer: Steve Layland <layland@wolfram.com> (Invalid email address)
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
4 " Doug Kearns <dougkearns@gmail.com>
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
5 " Last Change: Sat May 10 18:56:22 CDT 2005
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
6 " 2022 April: b:undo_indent added by Doug Kearns
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
7 " Source: http://vim.sourceforge.net/scripts/script.php?script_id=1274
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
8 " http://members.wolfram.com/layland/vim/indent/mma.vim
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
9 "
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
10 " NOTE:
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
11 " Empty .m files will automatically be presumed to be Matlab files
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
12 " unless you have the following in your .vimrc:
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
13 "
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
14 " let filetype_m="mma"
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
15 "
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
16 " Credits:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
17 " 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
18 " distribution that he no longer remembers...sh.vim? Thanks!
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
19
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
20 " Only load this indent file when no other was loaded.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
21 if exists("b:did_indent")
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
22 finish
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
23 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
24 let b:did_indent = 1
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
25
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
26 setlocal indentexpr=GetMmaIndent()
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
27 setlocal indentkeys+=0[,0],0(,0)
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
28 setlocal nosi "turn off smart indent so we don't over analyze } blocks
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
29
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
30 let b:undo_indent = "setl inde< indk< si<"
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
31
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
32 if exists("*GetMmaIndent")
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
33 finish
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
34 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
35
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
36 function GetMmaIndent()
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
37
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
38 " Hit the start of the file, use zero indent.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
39 if v:lnum == 0
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
40 return 0
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
41 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
42
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
43 " Find a non-blank line above the current line.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
44 let lnum = prevnonblank(v:lnum - 1)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
45
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
46 " use indenting as a base
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
47 let ind = indent(v:lnum)
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
48 let lnum = v:lnum
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
49
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
50 " if previous line has an unmatched bracket, or ( indent.
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
51 " doesn't do multiple parens/blocks/etc...
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
52
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
53 " also, indent only if this line if this line isn't starting a new
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
54 " block... TODO - fix this with indentkeys?
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
55 if getline(v:lnum-1) =~ '\\\@<!\%(\[[^\]]*\|([^)]*\|{[^}]*\)$' && getline(v:lnum) !~ '\s\+[\[({]'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 856
diff changeset
56 let ind = ind+shiftwidth()
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
57 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
58
856
8cd729851562 updated for version 7.0g
vimboss
parents: 271
diff changeset
59 " if this line had unmatched closing block,
271
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
60 " indent to the matching opening block
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
61 if getline(v:lnum) =~ '[^[]*]\s*$'
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
62 " move to the closing bracket
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
63 call search(']','bW')
16610
1eaf34420bb3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
64 " and find its partner's indent
271
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 " same for ( blocks
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
67 elseif getline(v:lnum) =~ '[^(]*)$'
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
68 call search(')','bW')
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
69 let ind = indent(searchpair('(','',')','bWn'))
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
70
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
71 " and finally, close { blocks if si ain't already set
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
72 elseif getline(v:lnum) =~ '[^{]*}'
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
73 call search('}','bW')
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
74 let ind = indent(searchpair('{','','}','bWn'))
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
75 endif
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
76
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
77 return ind
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
78 endfunction
8d34af900bae updated for version 7.0072
vimboss
parents:
diff changeset
79