531
|
1 " Vim completion script
|
|
2 " Language: CSS 2.1
|
|
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
|
553
|
4 " Last Change: 2005 Oct 12
|
531
|
5
|
|
6 function! csscomplete#CompleteCSS(findstart, base)
|
|
7 if a:findstart
|
|
8 " We need whole line to proper checking
|
548
|
9 let line = getline('.')
|
|
10 let start = col('.') - 1
|
|
11 let compl_begin = col('.') - 2
|
|
12 while start >= 0 && line[start - 1] =~ '\(\k\|-\)'
|
|
13 let start -= 1
|
|
14 endwhile
|
|
15 let b:compl_context = getline('.')[0:compl_begin]
|
|
16 return start
|
531
|
17 else
|
|
18 " There are few chars important for context:
|
|
19 " ^ ; : { } /* */
|
|
20 " Where ^ is start of line and /* */ are comment borders
|
|
21 " Depending on their relative position to cursor we will now what should
|
|
22 " be completed.
|
|
23 " 1. if nearest are ^ or { or ; current word is property
|
548
|
24 " 2. if : it is value (with exception of pseudo things)
|
531
|
25 " 3. if } we are outside of css definitions
|
|
26 " 4. for comments ignoring is be the easiest but assume they are the same
|
|
27 " as 1.
|
532
|
28 " 5. if @ complete at-rule
|
|
29 " 6. if ! complete important
|
553
|
30 if exists("b:compl_context")
|
|
31 let line = b:compl_context
|
|
32 unlet! b:compl_context
|
|
33 else
|
|
34 let line = a:base
|
|
35 endif
|
548
|
36
|
531
|
37 let res = []
|
|
38 let res2 = []
|
|
39 let borders = {}
|
|
40
|
|
41 " We need the last occurrence of char so reverse line
|
|
42 let revline = join(reverse(split(line, '.\zs')), '')
|
532
|
43
|
531
|
44 let openbrace = stridx(revline, '{')
|
|
45 let closebrace = stridx(revline, '}')
|
532
|
46 let colon = stridx(revline, ':')
|
|
47 let semicolon = stridx(revline, ';')
|
|
48 let opencomm = stridx(revline, '*/') " Line was reversed
|
|
49 let closecomm = stridx(revline, '/*') " Line was reversed
|
|
50 let style = stridx(revline, '=\s*elyts') " Line was reversed
|
|
51 let atrule = stridx(revline, '@')
|
|
52 let exclam = stridx(revline, '!')
|
531
|
53
|
|
54 if openbrace > -1
|
|
55 let borders[openbrace] = "openbrace"
|
|
56 endif
|
|
57 if closebrace > -1
|
|
58 let borders[closebrace] = "closebrace"
|
|
59 endif
|
|
60 if colon > -1
|
|
61 let borders[colon] = "colon"
|
|
62 endif
|
|
63 if semicolon > -1
|
|
64 let borders[semicolon] = "semicolon"
|
|
65 endif
|
|
66 if opencomm > -1
|
|
67 let borders[opencomm] = "opencomm"
|
|
68 endif
|
|
69 if closecomm > -1
|
|
70 let borders[closecomm] = "closecomm"
|
|
71 endif
|
|
72 if style > -1
|
|
73 let borders[style] = "style"
|
|
74 endif
|
|
75 if atrule > -1
|
|
76 let borders[atrule] = "atrule"
|
|
77 endif
|
532
|
78 if exclam > -1
|
|
79 let borders[exclam] = "exclam"
|
|
80 endif
|
531
|
81
|
548
|
82
|
531
|
83 if len(borders) == 0 || borders[min(keys(borders))] =~ '^\(openbrace\|semicolon\|opencomm\|closecomm\|style\)$'
|
|
84 " Complete properties
|
|
85
|
548
|
86 let values = split("azimuth background background-attachment background-color background-image background-position background-repeat border bottom border-collapse border-color border-spacing border-style border-top border-right border-bottom border-left border-top-color border-right-color border-bottom-color border-left-color border-top-style border-right-style border-bottom-style border-left-style border-top-width border-right-width border-bottom-width border-left-width border-width caption-side clear clip color content counter-increment counter-reset cue cue-after cue-before cursor display direction elevation empty-cells float font font-family font-size font-style font-variant font-weight height left letter-spacing line-height list-style list-style-image list-style-position list-style-type margin margin-right margin-left margin-top margin-bottom max-height max-width min-height min-width orphans outline outline-color outline-style outline-width overflow padding padding-top padding-right padding-bottom padding-left page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position quotes right richness speak speak-header speak-numeral speak-punctuation speech-rate stress table-layout text-align text-decoration text-indent text-transform top unicode-bidi vertical-align visibility voice-family volume white-space width widows word-spacing z-index")
|
531
|
87
|
|
88 let entered_property = matchstr(line, '.\{-}\zs[a-zA-Z-]*$')
|
|
89
|
|
90 for m in values
|
|
91 if m =~? '^'.entered_property
|
548
|
92 call add(res, m . ':')
|
531
|
93 elseif m =~? entered_property
|
548
|
94 call add(res2, m . ':')
|
531
|
95 endif
|
|
96 endfor
|
|
97
|
|
98 return res + res2
|
|
99
|
|
100 elseif borders[min(keys(borders))] == 'colon'
|
|
101 " Get name of property
|
|
102 let prop = tolower(matchstr(line, '\zs[a-zA-Z-]*\ze\s*:[^:]\{-}$'))
|
|
103
|
|
104 if prop == 'azimuth'
|
|
105 let values = ["left-side", "far-left", "left", "center-left", "center", "center-right", "right", "far-right", "right-side", "behind", "leftwards", "rightwards"]
|
|
106 elseif prop == 'background-attachment'
|
|
107 let values = ["scroll", "fixed"]
|
|
108 elseif prop == 'background-color'
|
|
109 let values = ["transparent", "rgb(", "#"]
|
|
110 elseif prop == 'background-image'
|
|
111 let values = ["url(", "none"]
|
|
112 elseif prop == 'background-position'
|
|
113 let vals = matchstr(line, '.*:\s*\zs.*')
|
|
114 if vals =~ '^\([a-zA-Z]\+\)\?$'
|
|
115 let values = ["top", "center", "bottom"]
|
|
116 elseif vals =~ '^[a-zA-Z]\+\s\+\([a-zA-Z]\+\)\?$'
|
|
117 let values = ["left", "center", "right"]
|
|
118 else
|
|
119 return []
|
|
120 endif
|
|
121 elseif prop == 'background-repeat'
|
|
122 let values = ["repeat", "repeat-x", "repeat-y", "no-repeat"]
|
|
123 elseif prop == 'background'
|
|
124 let values = ["url(", "scroll", "fixed", "transparent", "rgb(", "#", "none", "top", "center", "bottom" , "left", "right", "repeat", "repeat-x", "repeat-y", "no-repeat"]
|
|
125 elseif prop == 'border-collapse'
|
|
126 let values = ["collapse", "separate"]
|
|
127 elseif prop == 'border-color'
|
|
128 let values = ["rgb(", "#", "transparent"]
|
|
129 elseif prop == 'border-spacing'
|
|
130 return []
|
|
131 elseif prop == 'border-style'
|
|
132 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
|
133 elseif prop =~ 'border-\(top\|right\|bottom\|left\)$'
|
|
134 let vals = matchstr(line, '.*:\s*\zs.*')
|
|
135 if vals =~ '^\([a-zA-Z0-9.]\+\)\?$'
|
|
136 let values = ["thin", "thick", "medium"]
|
|
137 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+\([a-zA-Z]\+\)\?$'
|
|
138 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
|
139 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+[a-zA-Z]\+\s\+\([a-zA-Z(]\+\)\?$'
|
|
140 let values = ["rgb(", "#", "transparent"]
|
|
141 else
|
|
142 return []
|
|
143 endif
|
|
144 elseif prop =~ 'border-\(top\|right\|bottom\|left\)-color'
|
|
145 let values = ["rgb(", "#", "transparent"]
|
|
146 elseif prop =~ 'border-\(top\|right\|bottom\|left\)-style'
|
|
147 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
|
148 elseif prop =~ 'border-\(top\|right\|bottom\|left\)-width'
|
|
149 let values = ["thin", "thick", "medium"]
|
|
150 elseif prop == 'border-width'
|
|
151 let values = ["thin", "thick", "medium"]
|
|
152 elseif prop == 'border'
|
|
153 let vals = matchstr(line, '.*:\s*\zs.*')
|
|
154 if vals =~ '^\([a-zA-Z0-9.]\+\)\?$'
|
|
155 let values = ["thin", "thick", "medium"]
|
|
156 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+\([a-zA-Z]\+\)\?$'
|
|
157 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
|
158 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+[a-zA-Z]\+\s\+\([a-zA-Z(]\+\)\?$'
|
|
159 let values = ["rgb(", "#", "transparent"]
|
|
160 else
|
|
161 return []
|
|
162 endif
|
|
163 elseif prop == 'bottom'
|
|
164 let values = ["auto"]
|
|
165 elseif prop == 'caption-side'
|
|
166 let values = ["top", "bottom"]
|
|
167 elseif prop == 'clear'
|
|
168 let values = ["none", "left", "right", "both"]
|
|
169 elseif prop == 'clip'
|
|
170 let values = ["auto", "rect("]
|
|
171 elseif prop == 'color'
|
|
172 let values = ["rgb(", "#"]
|
|
173 elseif prop == 'content'
|
|
174 let values = ["normal", "attr(", "open-quote", "close-quote", "no-open-quote", "no-close-quote"]
|
|
175 elseif prop =~ 'counter-\(increment\|reset\)$'
|
|
176 let values = ["none"]
|
|
177 elseif prop =~ '^\(cue-after\|cue-before\|cue\)$'
|
|
178 let values = ["url(", "none"]
|
|
179 elseif prop == 'cursor'
|
|
180 let values = ["url(", "auto", "crosshair", "default", "pointer", "move", "e-resize", "ne-resize", "nw-resize", "n-resize", "se-resize", "sw-resize", "s-resize", "w-resize", "text", "wait", "help", "progress"]
|
|
181 elseif prop == 'direction'
|
|
182 let values = ["ltr", "rtl"]
|
|
183 elseif prop == 'display'
|
|
184 let values = ["inline", "block", "list-item", "run-in", "inline-block", "table", "inline-table", "table-row-group", "table-header-group", "table-footer-group", "table-row", "table-column-group", "table-column", "table-cell", "table-caption", "none"]
|
|
185 elseif prop == 'elevation'
|
|
186 let values = ["below", "level", "above", "higher", "lower"]
|
|
187 elseif prop == 'empty-cells'
|
|
188 let values = ["show", "hide"]
|
|
189 elseif prop == 'float'
|
|
190 let values = ["left", "right", "none"]
|
|
191 elseif prop == 'font-family'
|
|
192 let values = ["sans-serif", "serif", "monospace", "cursive", "fantasy"]
|
|
193 elseif prop == 'font-size'
|
539
|
194 let values = ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "larger", "smaller"]
|
531
|
195 elseif prop == 'font-style'
|
|
196 let values = ["normal", "italic", "oblique"]
|
|
197 elseif prop == 'font-variant'
|
|
198 let values = ["normal", "small-caps"]
|
|
199 elseif prop == 'font-weight'
|
|
200 let values = ["normal", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900"]
|
|
201 elseif prop == 'font'
|
539
|
202 let values = ["normal", "italic", "oblique", "small-caps", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900", "xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "larger", "smaller", "sans-serif", "serif", "monospace", "cursive", "fantasy", "caption", "icon", "menu", "message-box", "small-caption", "status-bar"]
|
531
|
203 elseif prop =~ '^\(height\|width\)$'
|
|
204 let values = ["auto"]
|
|
205 elseif prop =~ '^\(left\|rigth\)$'
|
|
206 let values = ["auto"]
|
|
207 elseif prop == 'letter-spacing'
|
|
208 let values = ["normal"]
|
|
209 elseif prop == 'line-height'
|
|
210 let values = ["normal"]
|
|
211 elseif prop == 'list-style-image'
|
|
212 let values = ["url(", "none"]
|
|
213 elseif prop == 'list-style-position'
|
|
214 let values = ["inside", "outside"]
|
|
215 elseif prop == 'list-style-type'
|
|
216 let values = ["disc", "circle", "square", "decimal", "decimal-leading-zero", "lower-roman", "upper-roman", "lower-latin", "upper-latin", "none"]
|
|
217 elseif prop == 'list-style'
|
|
218 return []
|
|
219 elseif prop == 'margin'
|
|
220 let values = ["auto"]
|
|
221 elseif prop =~ 'margin-\(right\|left\|top\|bottom\)$'
|
|
222 let values = ["auto"]
|
|
223 elseif prop == 'max-height'
|
|
224 let values = ["auto"]
|
|
225 elseif prop == 'max-width'
|
|
226 let values = ["none"]
|
|
227 elseif prop == 'min-height'
|
|
228 let values = ["none"]
|
|
229 elseif prop == 'min-width'
|
|
230 let values = ["none"]
|
|
231 elseif prop == 'orphans'
|
|
232 return []
|
|
233 elseif prop == 'outline-color'
|
|
234 let values = ["rgb(", "#"]
|
|
235 elseif prop == 'outline-style'
|
|
236 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
|
237 elseif prop == 'outline-width'
|
|
238 let values = ["thin", "thick", "medium"]
|
|
239 elseif prop == 'outline'
|
|
240 let vals = matchstr(line, '.*:\s*\zs.*')
|
|
241 if vals =~ '^\([a-zA-Z0-9,()#]\+\)\?$'
|
|
242 let values = ["rgb(", "#"]
|
|
243 elseif vals =~ '^[a-zA-Z0-9,()#]\+\s\+\([a-zA-Z]\+\)\?$'
|
|
244 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
|
|
245 elseif vals =~ '^[a-zA-Z0-9,()#]\+\s\+[a-zA-Z]\+\s\+\([a-zA-Z(]\+\)\?$'
|
|
246 let values = ["thin", "thick", "medium"]
|
|
247 else
|
|
248 return []
|
|
249 endif
|
|
250 elseif prop == 'overflow'
|
|
251 let values = ["visible", "hidden", "scroll", "auto"]
|
|
252 elseif prop == 'padding'
|
|
253 return []
|
|
254 elseif prop =~ 'padding-\(top\|right\|bottom\|left\)$'
|
|
255 return []
|
|
256 elseif prop =~ 'page-break-\(after\|before\)$'
|
|
257 let values = ["auto", "always", "avoid", "left", "right"]
|
|
258 elseif prop == 'page-break-inside'
|
|
259 let values = ["auto", "avoid"]
|
|
260 elseif prop =~ 'pause-\(after\|before\)$'
|
|
261 return []
|
|
262 elseif prop == 'pause'
|
|
263 return []
|
|
264 elseif prop == 'pitch-range'
|
|
265 return []
|
|
266 elseif prop == 'pitch'
|
|
267 let values = ["x-low", "low", "medium", "high", "x-high"]
|
|
268 elseif prop == 'play-during'
|
|
269 let values = ["url(", "mix", "repeat", "auto", "none"]
|
|
270 elseif prop == 'position'
|
|
271 let values = ["static", "relative", "absolute", "fixed"]
|
|
272 elseif prop == 'quotes'
|
|
273 let values = ["none"]
|
|
274 elseif prop == 'richness'
|
|
275 return []
|
|
276 elseif prop == 'speak-header'
|
|
277 let values = ["once", "always"]
|
|
278 elseif prop == 'speak-numeral'
|
|
279 let values = ["digits", "continuous"]
|
|
280 elseif prop == 'speak-punctuation'
|
|
281 let values = ["code", "none"]
|
|
282 elseif prop == 'speak'
|
|
283 let values = ["normal", "none", "spell-out"]
|
|
284 elseif prop == 'speech-rate'
|
|
285 let values = ["x-slow", "slow", "medium", "fast", "x-fast", "faster", "slower"]
|
|
286 elseif prop == 'stress'
|
|
287 return []
|
|
288 elseif prop == 'table-layout'
|
|
289 let values = ["auto", "fixed"]
|
|
290 elseif prop == 'text-align'
|
|
291 let values = ["left", "right", "center", "justify"]
|
|
292 elseif prop == 'text-decoration'
|
|
293 let values = ["none", "underline", "overline", "line-through", "blink"]
|
|
294 elseif prop == 'text-indent'
|
|
295 return []
|
|
296 elseif prop == 'text-transform'
|
|
297 let values = ["capitalize", "uppercase", "lowercase", "none"]
|
|
298 elseif prop == 'top'
|
|
299 let values = ["auto"]
|
|
300 elseif prop == 'unicode-bidi'
|
|
301 let values = ["normal", "embed", "bidi-override"]
|
|
302 elseif prop == 'vertical-align'
|
|
303 let values = ["baseline", "sub", "super", "top", "text-top", "middle", "bottom", "text-bottom"]
|
|
304 elseif prop == 'visibility'
|
|
305 let values = ["visible", "hidden", "collapse"]
|
|
306 elseif prop == 'voice-family'
|
|
307 return []
|
|
308 elseif prop == 'volume'
|
|
309 let values = ["silent", "x-soft", "soft", "medium", "loud", "x-loud"]
|
|
310 elseif prop == 'white-space'
|
|
311 let values = ["normal", "pre", "nowrap", "pre-wrap", "pre-line"]
|
|
312 elseif prop == 'widows'
|
|
313 return []
|
|
314 elseif prop == 'word-spacing'
|
|
315 let values = ["normal"]
|
|
316 elseif prop == 'z-index'
|
|
317 let values = ["auto"]
|
|
318 else
|
534
|
319 " If no property match it is possible we are outside of {} and
|
|
320 " trying to complete pseudo-(class|element)
|
|
321 let element = tolower(matchstr(line, '\zs[a-zA-Z1-6]*\ze:[^:[:space:]]\{-}$'))
|
|
322 if ",a,abbr,acronym,address,area,b,base,bdo,big,blockquote,body,br,button,caption,cite,code,col,colgroup,dd,del,dfn,div,dl,dt,em,fieldset,form,head,h1,h2,h3,h4,h5,h6,hr,html,i,img,input,ins,kbd,label,legend,li,link,map,meta,noscript,object,ol,optgroup,option,p,param,pre,q,samp,script,select,small,span,strong,style,sub,sup,table,tbody,td,textarea,tfoot,th,thead,title,tr,tt,ul,var," =~ ','.element.','
|
|
323 let values = ["first-child", "link", "visited", "hover", "active", "focus", "lang", "first-line", "first-letter", "before", "after"]
|
|
324 else
|
|
325 return []
|
|
326 endif
|
531
|
327 endif
|
|
328
|
|
329 " Complete values
|
|
330 let entered_value = matchstr(line, '.\{-}\zs[a-zA-Z0-9#,.(_-]*$')
|
|
331
|
|
332 for m in values
|
|
333 if m =~? '^'.entered_value
|
548
|
334 call add(res, m)
|
531
|
335 elseif m =~? entered_value
|
548
|
336 call add(res2, m)
|
531
|
337 endif
|
|
338 endfor
|
|
339
|
|
340 return res + res2
|
|
341
|
|
342 elseif borders[min(keys(borders))] == 'closebrace'
|
|
343
|
|
344 return []
|
|
345
|
532
|
346 elseif borders[min(keys(borders))] == 'exclam'
|
|
347
|
|
348 " Complete values
|
|
349 let entered_imp = matchstr(line, '.\{-}!\s*\zs[a-zA-Z ]*$')
|
|
350
|
|
351 let values = ["important"]
|
|
352
|
|
353 for m in values
|
|
354 if m =~? '^'.entered_imp
|
548
|
355 call add(res, m)
|
532
|
356 endif
|
|
357 endfor
|
|
358
|
|
359 return res
|
|
360
|
531
|
361 elseif borders[min(keys(borders))] == 'atrule'
|
|
362
|
|
363 let afterat = matchstr(line, '.*@\zs.*')
|
|
364
|
|
365 if afterat =~ '\s'
|
|
366
|
|
367 let atrulename = matchstr(line, '.*@\zs[a-zA-Z-]\+\ze')
|
|
368
|
|
369 if atrulename == 'media'
|
|
370 let values = ["screen", "tty", "tv", "projection", "handheld", "print", "braille", "aural", "all"]
|
|
371
|
|
372 let atruleafterbase = matchstr(line, '.*@media\s\+\ze.*$')
|
|
373 let entered_atruleafter = matchstr(line, '.*@media\s\+\zs.*$')
|
|
374
|
|
375 elseif atrulename == 'import'
|
|
376 let atruleafterbase = matchstr(line, '.*@import\s\+\ze.*$')
|
|
377 let entered_atruleafter = matchstr(line, '.*@import\s\+\zs.*$')
|
|
378
|
|
379 if entered_atruleafter =~ "^[\"']"
|
|
380 let filestart = matchstr(entered_atruleafter, '^.\zs.*')
|
|
381 let files = split(glob(filestart.'*'), '\n')
|
|
382 let values = map(copy(files), '"\"".v:val')
|
|
383
|
|
384 elseif entered_atruleafter =~ "^url("
|
|
385 let filestart = matchstr(entered_atruleafter, "^url([\"']\\?\\zs.*")
|
|
386 let files = split(glob(filestart.'*'), '\n')
|
|
387 let values = map(copy(files), '"url(".v:val')
|
|
388
|
|
389 else
|
|
390 let values = ['"', 'url(']
|
|
391
|
|
392 endif
|
|
393
|
|
394 else
|
|
395 return []
|
|
396
|
|
397 endif
|
|
398
|
|
399 for m in values
|
|
400 if m =~? '^'.entered_atruleafter
|
548
|
401 call add(res, m)
|
531
|
402 elseif m =~? entered_atruleafter
|
548
|
403 call add(res2, m)
|
531
|
404 endif
|
|
405 endfor
|
|
406
|
|
407 return res + res2
|
|
408
|
|
409 endif
|
|
410
|
532
|
411 let values = ["charset", "page", "media", "import", "font-face"]
|
531
|
412
|
|
413 let entered_atrule = matchstr(line, '.*@\zs[a-zA-Z-]*$')
|
|
414
|
|
415 for m in values
|
|
416 if m =~? '^'.entered_atrule
|
548
|
417 call add(res, m .' ')
|
531
|
418 elseif m =~? entered_atrule
|
548
|
419 call add(res2, m .' ')
|
531
|
420 endif
|
|
421 endfor
|
|
422
|
|
423 return res + res2
|
|
424
|
|
425 endif
|
|
426
|
|
427 return []
|
|
428
|
|
429 endif
|
|
430 endfunction
|