1 " Vim completion script
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
4 " Last Change: 2007 May 5
6 let s: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")
8 function! csscomplete#CompleteCSS(findstart, base)
11 " We need whole line to proper checking
12 let line = getline('.')
13 let start = col('.') - 1
14 let compl_begin = col('.') - 2
15 while start >= 0 && line[start - 1] =~ '\%(\k\|-\)'
18 let b:compl_context = line[0:compl_begin]
22 " There are few chars important for context:
24 " Where ^ is start of line and /* */ are comment borders
25 " Depending on their relative position to cursor we will know what should
27 " 1. if nearest are ^ or { or ; current word is property
28 " 2. if : it is value (with exception of pseudo things)
29 " 3. if } we are outside of css definitions
30 " 4. for comments ignoring is be the easiest but assume they are the same
32 " 5. if @ complete at-rule
33 " 6. if ! complete important
34 if exists("b:compl_context")
35 let line = b:compl_context
36 unlet! b:compl_context
45 " Check last occurrence of sequence
47 let openbrace = strridx(line, '{')
48 let closebrace = strridx(line, '}')
49 let colon = strridx(line, ':')
50 let semicolon = strridx(line, ';')
51 let opencomm = strridx(line, '/*')
52 let closecomm = strridx(line, '*/')
53 let style = strridx(line, 'style\s*=')
54 let atrule = strridx(line, '@')
55 let exclam = strridx(line, '!')
58 let borders[openbrace] = "openbrace"
61 let borders[closebrace] = "closebrace"
64 let borders[colon] = "colon"
67 let borders[semicolon] = "semicolon"
70 let borders[opencomm] = "opencomm"
73 let borders[closecomm] = "closecomm"
76 let borders[style] = "style"
79 let borders[atrule] = "atrule"
82 let borders[exclam] = "exclam"
86 if len(borders) == 0 || borders[max(keys(borders))] =~ '^\%(openbrace\|semicolon\|opencomm\|closecomm\|style\)$'
90 let entered_property = matchstr(line, '.\{-}\zs[a-zA-Z-]*$')
93 if m =~? '^'.entered_property
94 call add(res, m . ':')
95 elseif m =~? entered_property
96 call add(res2, m . ':')
102 elseif borders[max(keys(borders))] == 'colon'
103 " Get name of property
104 let prop = tolower(matchstr(line, '\zs[a-zA-Z-]*\ze\s*:[^:]\{-}$'))
107 let values = ["left-side", "far-left", "left", "center-left", "center", "center-right", "right", "far-right", "right-side", "behind", "leftwards", "rightwards"]
108 elseif prop == 'background-attachment'
109 let values = ["scroll", "fixed"]
110 elseif prop == 'background-color'
111 let values = ["transparent", "rgb(", "#"]
112 elseif prop == 'background-image'
113 let values = ["url(", "none"]
114 elseif prop == 'background-position'
115 let vals = matchstr(line, '.*:\s*\zs.*')
116 if vals =~ '^\%([a-zA-Z]\+\)\?$'
117 let values = ["top", "center", "bottom"]
118 elseif vals =~ '^[a-zA-Z]\+\s\+\%([a-zA-Z]\+\)\?$'
119 let values = ["left", "center", "right"]
123 elseif prop == 'background-repeat'
124 let values = ["repeat", "repeat-x", "repeat-y", "no-repeat"]
125 elseif prop == 'background'
126 let values = ["url(", "scroll", "fixed", "transparent", "rgb(", "#", "none", "top", "center", "bottom" , "left", "right", "repeat", "repeat-x", "repeat-y", "no-repeat"]
127 elseif prop == 'border-collapse'
128 let values = ["collapse", "separate"]
129 elseif prop == 'border-color'
130 let values = ["rgb(", "#", "transparent"]
131 elseif prop == 'border-spacing'
133 elseif prop == 'border-style'
134 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
135 elseif prop =~ 'border-\%(top\|right\|bottom\|left\)$'
136 let vals = matchstr(line, '.*:\s*\zs.*')
137 if vals =~ '^\%([a-zA-Z0-9.]\+\)\?$'
138 let values = ["thin", "thick", "medium"]
139 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+\%([a-zA-Z]\+\)\?$'
140 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
141 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+[a-zA-Z]\+\s\+\%([a-zA-Z(]\+\)\?$'
142 let values = ["rgb(", "#", "transparent"]
146 elseif prop =~ 'border-\%(top\|right\|bottom\|left\)-color'
147 let values = ["rgb(", "#", "transparent"]
148 elseif prop =~ 'border-\%(top\|right\|bottom\|left\)-style'
149 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
150 elseif prop =~ 'border-\%(top\|right\|bottom\|left\)-width'
151 let values = ["thin", "thick", "medium"]
152 elseif prop == 'border-width'
153 let values = ["thin", "thick", "medium"]
154 elseif prop == 'border'
155 let vals = matchstr(line, '.*:\s*\zs.*')
156 if vals =~ '^\%([a-zA-Z0-9.]\+\)\?$'
157 let values = ["thin", "thick", "medium"]
158 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+\%([a-zA-Z]\+\)\?$'
159 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
160 elseif vals =~ '^[a-zA-Z0-9.]\+\s\+[a-zA-Z]\+\s\+\%([a-zA-Z(]\+\)\?$'
161 let values = ["rgb(", "#", "transparent"]
165 elseif prop == 'bottom'
166 let values = ["auto"]
167 elseif prop == 'caption-side'
168 let values = ["top", "bottom"]
169 elseif prop == 'clear'
170 let values = ["none", "left", "right", "both"]
171 elseif prop == 'clip'
172 let values = ["auto", "rect("]
173 elseif prop == 'color'
174 let values = ["rgb(", "#"]
175 elseif prop == 'content'
176 let values = ["normal", "attr(", "open-quote", "close-quote", "no-open-quote", "no-close-quote"]
177 elseif prop =~ 'counter-\%(increment\|reset\)$'
178 let values = ["none"]
179 elseif prop =~ '^\%(cue-after\|cue-before\|cue\)$'
180 let values = ["url(", "none"]
181 elseif prop == 'cursor'
182 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"]
183 elseif prop == 'direction'
184 let values = ["ltr", "rtl"]
185 elseif prop == 'display'
186 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"]
187 elseif prop == 'elevation'
188 let values = ["below", "level", "above", "higher", "lower"]
189 elseif prop == 'empty-cells'
190 let values = ["show", "hide"]
191 elseif prop == 'float'
192 let values = ["left", "right", "none"]
193 elseif prop == 'font-family'
194 let values = ["sans-serif", "serif", "monospace", "cursive", "fantasy"]
195 elseif prop == 'font-size'
196 let values = ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "larger", "smaller"]
197 elseif prop == 'font-style'
198 let values = ["normal", "italic", "oblique"]
199 elseif prop == 'font-variant'
200 let values = ["normal", "small-caps"]
201 elseif prop == 'font-weight'
202 let values = ["normal", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900"]
203 elseif prop == 'font'
204 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"]
205 elseif prop =~ '^\%(height\|width\)$'
206 let values = ["auto"]
207 elseif prop =~ '^\%(left\|rigth\)$'
208 let values = ["auto"]
209 elseif prop == 'letter-spacing'
210 let values = ["normal"]
211 elseif prop == 'line-height'
212 let values = ["normal"]
213 elseif prop == 'list-style-image'
214 let values = ["url(", "none"]
215 elseif prop == 'list-style-position'
216 let values = ["inside", "outside"]
217 elseif prop == 'list-style-type'
218 let values = ["disc", "circle", "square", "decimal", "decimal-leading-zero", "lower-roman", "upper-roman", "lower-latin", "upper-latin", "none"]
219 elseif prop == 'list-style'
221 elseif prop == 'margin'
222 let values = ["auto"]
223 elseif prop =~ 'margin-\%(right\|left\|top\|bottom\)$'
224 let values = ["auto"]
225 elseif prop == 'max-height'
226 let values = ["auto"]
227 elseif prop == 'max-width'
228 let values = ["none"]
229 elseif prop == 'min-height'
230 let values = ["none"]
231 elseif prop == 'min-width'
232 let values = ["none"]
233 elseif prop == 'orphans'
235 elseif prop == 'outline-color'
236 let values = ["rgb(", "#"]
237 elseif prop == 'outline-style'
238 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
239 elseif prop == 'outline-width'
240 let values = ["thin", "thick", "medium"]
241 elseif prop == 'outline'
242 let vals = matchstr(line, '.*:\s*\zs.*')
243 if vals =~ '^\%([a-zA-Z0-9,()#]\+\)\?$'
244 let values = ["rgb(", "#"]
245 elseif vals =~ '^[a-zA-Z0-9,()#]\+\s\+\%([a-zA-Z]\+\)\?$'
246 let values = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"]
247 elseif vals =~ '^[a-zA-Z0-9,()#]\+\s\+[a-zA-Z]\+\s\+\%([a-zA-Z(]\+\)\?$'
248 let values = ["thin", "thick", "medium"]
252 elseif prop == 'overflow'
253 let values = ["visible", "hidden", "scroll", "auto"]
254 elseif prop == 'padding'
256 elseif prop =~ 'padding-\%(top\|right\|bottom\|left\)$'
258 elseif prop =~ 'page-break-\%(after\|before\)$'
259 let values = ["auto", "always", "avoid", "left", "right"]
260 elseif prop == 'page-break-inside'
261 let values = ["auto", "avoid"]
262 elseif prop =~ 'pause-\%(after\|before\)$'
264 elseif prop == 'pause'
266 elseif prop == 'pitch-range'
268 elseif prop == 'pitch'
269 let values = ["x-low", "low", "medium", "high", "x-high"]
270 elseif prop == 'play-during'
271 let values = ["url(", "mix", "repeat", "auto", "none"]
272 elseif prop == 'position'
273 let values = ["static", "relative", "absolute", "fixed"]
274 elseif prop == 'quotes'
275 let values = ["none"]
276 elseif prop == 'richness'
278 elseif prop == 'speak-header'
279 let values = ["once", "always"]
280 elseif prop == 'speak-numeral'
281 let values = ["digits", "continuous"]
282 elseif prop == 'speak-punctuation'
283 let values = ["code", "none"]
284 elseif prop == 'speak'
285 let values = ["normal", "none", "spell-out"]
286 elseif prop == 'speech-rate'
287 let values = ["x-slow", "slow", "medium", "fast", "x-fast", "faster", "slower"]
288 elseif prop == 'stress'
290 elseif prop == 'table-layout'
291 let values = ["auto", "fixed"]
292 elseif prop == 'text-align'
293 let values = ["left", "right", "center", "justify"]
294 elseif prop == 'text-decoration'
295 let values = ["none", "underline", "overline", "line-through", "blink"]
296 elseif prop == 'text-indent'
298 elseif prop == 'text-transform'
299 let values = ["capitalize", "uppercase", "lowercase", "none"]
301 let values = ["auto"]
302 elseif prop == 'unicode-bidi'
303 let values = ["normal", "embed", "bidi-override"]
304 elseif prop == 'vertical-align'
305 let values = ["baseline", "sub", "super", "top", "text-top", "middle", "bottom", "text-bottom"]
306 elseif prop == 'visibility'
307 let values = ["visible", "hidden", "collapse"]
308 elseif prop == 'voice-family'
310 elseif prop == 'volume'
311 let values = ["silent", "x-soft", "soft", "medium", "loud", "x-loud"]
312 elseif prop == 'white-space'
313 let values = ["normal", "pre", "nowrap", "pre-wrap", "pre-line"]
314 elseif prop == 'widows'
316 elseif prop == 'word-spacing'
317 let values = ["normal"]
318 elseif prop == 'z-index'
319 let values = ["auto"]
321 " If no property match it is possible we are outside of {} and
322 " trying to complete pseudo-(class|element)
323 let element = tolower(matchstr(line, '\zs[a-zA-Z1-6]*\ze:[^:[:space:]]\{-}$'))
324 if stridx(',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.',') > -1
325 let values = ["first-child", "link", "visited", "hover", "active", "focus", "lang", "first-line", "first-letter", "before", "after"]
332 let entered_value = matchstr(line, '.\{-}\zs[a-zA-Z0-9#,.(_-]*$')
335 if m =~? '^'.entered_value
337 elseif m =~? entered_value
344 elseif borders[max(keys(borders))] == 'closebrace'
348 elseif borders[max(keys(borders))] == 'exclam'
351 let entered_imp = matchstr(line, '.\{-}!\s*\zs[a-zA-Z ]*$')
353 let values = ["important"]
356 if m =~? '^'.entered_imp
363 elseif borders[max(keys(borders))] == 'atrule'
365 let afterat = matchstr(line, '.*@\zs.*')
369 let atrulename = matchstr(line, '.*@\zs[a-zA-Z-]\+\ze')
371 if atrulename == 'media'
372 let values = ["screen", "tty", "tv", "projection", "handheld", "print", "braille", "aural", "all"]
374 let entered_atruleafter = matchstr(line, '.*@media\s\+\zs.*$')
376 elseif atrulename == 'import'
377 let entered_atruleafter = matchstr(line, '.*@import\s\+\zs.*$')
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')
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')
390 let values = ['"', 'url(']
400 if m =~? '^'.entered_atruleafter
402 elseif m =~? entered_atruleafter
411 let values = ["charset", "page", "media", "import", "font-face"]
413 let entered_atrule = matchstr(line, '.*@\zs[a-zA-Z-]*$')
416 if m =~? '^'.entered_atrule
417 call add(res, m .' ')
418 elseif m =~? entered_atrule
419 call add(res2, m .' ')