Mercurial > vim
annotate runtime/syntax/xpm2.vim @ 22326:fb69b43d73f3 v8.2.1712
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Commit: https://github.com/vim/vim/commit/a05e524f3aa8eadc2dbd0ad8ff6db9407ac7ac7e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 19 18:19:19 2020 +0200
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Problem: Vim9: leaking memory when calling a lambda.
Solution: Decrement function reference from ISN_DCALL.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 19 Sep 2020 18:30:04 +0200 |
parents | c391bfbdb452 |
children |
rev | line source |
---|---|
7 | 1 " Vim syntax file |
2 " Language: X Pixmap v2 | |
3 " Maintainer: Steve Wall (hitched97@velnet.com) | |
10895
c391bfbdb452
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10051
diff
changeset
|
4 " Last Change: 2017 Feb 01 |
3557 | 5 " (Dominique Pelle added @Spell) |
7 | 6 " Version: 5.8 |
10895
c391bfbdb452
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10051
diff
changeset
|
7 " Jemma Nelson added termguicolors support |
7 | 8 " |
9 " Made from xpm.vim by Ronald Schild <rs@scutum.de> | |
10 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3557
diff
changeset
|
11 " quit when a syntax file was already loaded |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3557
diff
changeset
|
12 if exists("b:current_syntax") |
7 | 13 finish |
14 endif | |
15 | |
3312 | 16 let s:cpo_save = &cpo |
17 set cpo&vim | |
18 | |
7 | 19 syn region xpm2PixelString start="^" end="$" contains=@xpm2Colors |
20 syn keyword xpm2Todo TODO FIXME XXX contained | |
3557 | 21 syn match xpm2Comment "\!.*$" contains=@Spell,xpm2Todo |
7 | 22 |
23 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3557
diff
changeset
|
24 command -nargs=+ Hi hi def <args> |
7 | 25 |
10895
c391bfbdb452
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10051
diff
changeset
|
26 if has("gui_running") || has("termguicolors") && &termguicolors |
7 | 27 |
28 let color = "" | |
29 let chars = "" | |
30 let colors = 0 | |
31 let cpp = 0 | |
32 let n = 0 | |
33 let i = 1 | |
34 | |
35 while i <= line("$") " scanning all lines | |
36 | |
37 let s = getline(i) | |
38 if match(s,"\!.*$") != -1 | |
39 let s = matchstr(s, "^[^\!]*") | |
40 endif | |
41 if s != "" " does line contain a string? | |
42 | |
43 if n == 0 " first string is the Values string | |
44 | |
45 " get the 3rd value: colors = number of colors | |
46 let colors = substitute(s, '\s*\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '') | |
47 " get the 4th value: cpp = number of character per pixel | |
48 let cpp = substitute(s, '\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '') | |
1620 | 49 if cpp =~ '[^0-9]' |
50 break " if cpp is not made of digits there must be something wrong | |
51 endif | |
7 | 52 |
1620 | 53 " Highlight the Values string as normal string (no pixel string). |
54 " Only when there is no slash, it would terminate the pattern. | |
55 if s !~ '/' | |
56 exe 'syn match xpm2Values /' . s . '/' | |
57 endif | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
58 hi def link xpm2Values Statement |
7 | 59 |
60 let n = 1 " n = color index | |
61 | |
62 elseif n <= colors " string is a color specification | |
63 | |
64 " get chars = <cpp> length string representing the pixels | |
65 " (first incl. the following whitespace) | |
66 let chars = substitute(s, '\(.\{'.cpp.'}\s\+\).*', '\1', '') | |
67 | |
68 " now get color, first try 'c' key if any (color visual) | |
69 let color = substitute(s, '.*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*', '\1', '') | |
70 if color == s | |
71 " no 'c' key, try 'g' key (grayscale with more than 4 levels) | |
72 let color = substitute(s, '.*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*', '\1', '') | |
73 if color == s | |
74 " next try: 'g4' key (4-level grayscale) | |
75 let color = substitute(s, '.*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*', '\1', '') | |
76 if color == s | |
77 " finally try 'm' key (mono visual) | |
78 let color = substitute(s, '.*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*', '\1', '') | |
79 if color == s | |
80 let color = "" | |
81 endif | |
82 endif | |
83 endif | |
84 endif | |
85 | |
86 " Vim cannot handle RGB codes with more than 6 hex digits | |
87 if color =~ '#\x\{10,}$' | |
88 let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g') | |
89 elseif color =~ '#\x\{7,}$' | |
90 let color = substitute(color, '\(\x\x\)\x', '\1', 'g') | |
91 " nor with 3 digits | |
92 elseif color =~ '#\x\{3}$' | |
93 let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '') | |
94 endif | |
95 | |
96 " escape meta characters in patterns | |
97 let s = escape(s, '/\*^$.~[]') | |
98 let chars = escape(chars, '/\*^$.~[]') | |
99 | |
100 " change whitespace to "\s\+" | |
101 let s = substitute(s, "[ \t][ \t]*", "\\\\s\\\\+", "g") | |
102 let chars = substitute(chars, "[ \t][ \t]*", "\\\\s\\\\+", "g") | |
103 | |
104 " now create syntax items | |
105 " highlight the color string as normal string (no pixel string) | |
106 exe 'syn match xpm2Col'.n.'Def /'.s.'/ contains=xpm2Col'.n.'inDef' | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
107 exe 'hi def link xpm2Col'.n.'Def Constant' |
7 | 108 |
109 " but highlight the first whitespace after chars in its color | |
110 exe 'syn match xpm2Col'.n.'inDef /^'.chars.'/hs=s+'.(cpp).' contained' | |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
111 exe 'hi def link xpm2Col'.n.'inDef xpm2Color'.n |
7 | 112 |
113 " remove the following whitespace from chars | |
114 let chars = substitute(chars, '\\s\\+$', '', '') | |
115 | |
116 " and create the syntax item contained in the pixel strings | |
117 exe 'syn match xpm2Color'.n.' /'.chars.'/ contained' | |
118 exe 'syn cluster xpm2Colors add=xpm2Color'.n | |
119 | |
120 " if no color or color = "None" show background | |
121 if color == "" || substitute(color, '.*', '\L&', '') == 'none' | |
122 exe 'Hi xpm2Color'.n.' guifg=bg guibg=NONE' | |
1620 | 123 elseif color !~ "'" |
7 | 124 exe 'Hi xpm2Color'.n." guifg='".color."' guibg='".color."'" |
125 endif | |
126 let n = n + 1 | |
127 else | |
128 break " no more color string | |
129 endif | |
130 endif | |
131 let i = i + 1 | |
132 endwhile | |
133 | |
134 unlet color chars colors cpp n i s | |
135 | |
10895
c391bfbdb452
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10051
diff
changeset
|
136 endif " has("gui_running") || has("termguicolors") && &termguicolors |
7 | 137 |
138 " Define the default highlighting. | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3557
diff
changeset
|
139 " Only when an item doesn't have highlighting yet |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
3557
diff
changeset
|
140 " The default highlighting. |
10051
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
141 hi def link xpm2Type Type |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
142 hi def link xpm2StorageClass StorageClass |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
143 hi def link xpm2Todo Todo |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
144 hi def link xpm2Comment Comment |
46763b01cd9a
commit https://github.com/vim/vim/commit/f37506f60f87d52a9e8850e30067645e2b13783c
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
145 hi def link xpm2PixelString String |
7 | 146 |
147 delcommand Hi | |
148 | |
149 let b:current_syntax = "xpm2" | |
150 | |
3312 | 151 let &cpo = s:cpo_save |
152 unlet s:cpo_save | |
7 | 153 " vim: ts=8:sw=2:noet: |