annotate runtime/indent/tf.vim @ 16003:879829e44091 v8.1.1007

patch 8.1.1007: using closure may consume a lot of memory commit https://github.com/vim/vim/commit/209b8e3e3bf7a4a3d102134124120f6c7f57d560 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 14 13:43:24 2019 +0100 patch 8.1.1007: using closure may consume a lot of memory Problem: Using closure may consume a lot of memory. Solution: unreference items that are no longer needed. Add a test. (Ozaki Kiichi, closes #3961)
author Bram Moolenaar <Bram@vim.org>
date Thu, 14 Mar 2019 13:45:06 +0100
parents 1218c5353e2b
children 4d76b3e07c07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
1 " Vim indent file
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
2 " Language: tf (TinyFugue)
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 1624
diff changeset
3 " Maintainer: Christian J. Robinson <heptite@gmail.com>
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
4 " URL: http://www.vim.org/scripts/script.php?script_id=174
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
5 " Last Change: 2017 Feb 25
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
6
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
8 if exists("b:did_indent")
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
9 finish
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
10 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
11 let b:did_indent = 1
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
12
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
13 setlocal indentexpr=GetTFIndent()
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
14 setlocal indentkeys-=0{,0} indentkeys-=0# indentkeys-=:
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
15 setlocal indentkeys+==/endif,=/then,=/else,=/done,0;
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
16
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
17 " Only define the function once:
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
18 if exists("*GetTFIndent")
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
19 finish
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
20 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
21
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
22 function GetTFIndent()
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
23 " Find a non-blank line above the current line:
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
24 let lnum = prevnonblank(v:lnum - 1)
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
25
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
26 " No indent for the start of the file:
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
27 if lnum == 0
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
28 return 0
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
29 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
30
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
31 let ind = indent(lnum)
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
32 let line = getline(lnum)
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
33
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
34 " No indentation if the previous line didn't end with "\":
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
35 " (Could be annoying, but it lets you know if you made a mistake.)
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
36 if line !~ '\\$'
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
37 return 0
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
38 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
39
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
40 if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$'
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
41 let ind = ind + shiftwidth()
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
42 elseif line =~ '\(/if\|/else\|/then\)'
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
43 if line !~ '/endif'
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
44 let ind = ind + shiftwidth()
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
45 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
46 elseif line =~ '/while'
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
47 if line !~ '/done'
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
48 let ind = ind + shiftwidth()
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
49 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
50 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
51
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
52 let line = getline(v:lnum)
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
53
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
54 if line =~ '\(/else\|/endif\|/then\)'
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
55 if line !~ '/if'
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
56 let ind = ind - shiftwidth()
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
57 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
58 elseif line =~ '/done'
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
59 if line !~ '/while'
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 2239
diff changeset
60 let ind = ind - shiftwidth()
1624
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
61 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
62 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
63
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
64 " Comments at the beginning of a line:
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
65 if line =~ '^\s*;'
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
66 let ind = 0
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
67 endif
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
68
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
69
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
70 return ind
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
71
18ee39301b82 updated for version 7.2a
vimboss
parents:
diff changeset
72 endfunction