1 ;;; css-mode.el --- Major mode to edit CSS files -*- lexical-binding: t -*-
3 ;; Copyright (C) 2006-2017 Free Software Foundation, Inc.
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
6 ;; Maintainer: Simen Heggestøyl <simenheg@gmail.com>
7 ;; Keywords: hypermedia
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Yet another CSS mode.
30 ;; - filling code with auto-fill-mode
31 ;; - fix font-lock errors with multi-line selectors
39 (eval-when-compile (require 'subr-x
))
42 "Cascading Style Sheets (CSS) editing mode."
45 (defconst css-pseudo-class-ids
46 '("active" "checked" "disabled" "empty" "enabled" "first"
47 "first-child" "first-of-type" "focus" "hover" "indeterminate" "lang"
48 "last-child" "last-of-type" "left" "link" "not" "nth-child"
49 "nth-last-child" "nth-last-of-type" "nth-of-type" "only-child"
50 "only-of-type" "right" "root" "target" "visited")
51 "Identifiers for pseudo-classes.")
53 (defconst css-pseudo-element-ids
54 '("after" "before" "first-letter" "first-line")
55 "Identifiers for pseudo-elements.")
58 '("charset" "font-face" "import" "keyframes" "media" "namespace"
60 "Identifiers that appear in the form @foo.")
63 '("at-root" "content" "debug" "each" "else" "else if" "error" "extend"
64 "for" "function" "if" "import" "include" "mixin" "return" "warn"
66 "Additional identifiers that appear in the form @foo in SCSS.")
68 (defvar css--at-ids css-at-ids
69 "List of at-rules for the current mode.")
70 (make-variable-buffer-local 'css--at-ids
)
72 (defconst css-bang-ids
74 "Identifiers that appear in the form !foo.")
76 (defconst scss-bang-ids
77 '("default" "global" "optional")
78 "Additional identifiers that appear in the form !foo in SCSS.")
80 (defvar css--bang-ids css-bang-ids
81 "List of bang-rules for the current mode.")
82 (make-variable-buffer-local 'css--bang-ids
)
84 (defconst css-descriptor-ids
85 '("ascent" "baseline" "bbox" "cap-height" "centerline" "definition-src"
86 "descent" "font-family" "font-size" "font-stretch" "font-style"
87 "font-variant" "font-weight" "mathline" "panose-1" "slope" "src" "stemh"
88 "stemv" "topline" "unicode-range" "units-per-em" "widths" "x-height")
89 "Identifiers for font descriptors.")
91 (defconst css-media-ids
92 '("all" "aural" "bitmap" "continuous" "grid" "paged" "static" "tactile"
94 "Identifiers for types of media.")
96 (defconst css-property-alist
97 ;; CSS 2.1 properties (http://www.w3.org/TR/CSS21/propidx.html).
99 ;; Properties duplicated by any of the CSS3 modules below have been
101 '(("azimuth" angle
"left-side" "far-left" "left" "center-left"
102 "center" "center-right" "right" "far-right" "right-side" "behind"
103 "leftwards" "rightwards")
104 ("border-collapse" "collapse" "separate")
105 ("border-spacing" length
)
106 ("bottom" length percentage
"auto")
107 ("caption-side" "top" "bottom")
108 ("clear" "none" "left" "right" "both")
109 ("clip" shape
"auto")
110 ("content" "normal" "none" string uri counter
"attr()"
111 "open-quote" "close-quote" "no-open-quote" "no-close-quote")
112 ("counter-increment" identifier integer
"none")
113 ("counter-reset" identifier integer
"none")
114 ("cue" cue-before cue-after
)
115 ("cue-after" uri
"none")
116 ("cue-before" uri
"none")
117 ("direction" "ltr" "rtl")
118 ("display" "inline" "block" "list-item" "inline-block" "table"
119 "inline-table" "table-row-group" "table-header-group"
120 "table-footer-group" "table-row" "table-column-group"
121 "table-column" "table-cell" "table-caption" "none"
122 ;; CSS Flexible Box Layout Module Level 1
123 ;; (https://www.w3.org/TR/css3-flexbox/#valdef-display-flex)
124 "flex" "inline-flex")
125 ("elevation" angle
"below" "level" "above" "higher" "lower")
126 ("empty-cells" "show" "hide")
127 ("float" "left" "right" "none")
128 ("height" length percentage
"auto")
129 ("left" length percentage
"auto")
130 ("line-height" "normal" number length percentage
)
131 ("list-style" list-style-type list-style-position
133 ("list-style-image" uri
"none")
134 ("list-style-position" "inside" "outside")
135 ("list-style-type" "disc" "circle" "square" "decimal"
136 "decimal-leading-zero" "lower-roman" "upper-roman" "lower-greek"
137 "lower-latin" "upper-latin" "armenian" "georgian" "lower-alpha"
138 "upper-alpha" "none")
139 ("margin" margin-width
)
140 ("margin-bottom" margin-width
)
141 ("margin-left" margin-width
)
142 ("margin-right" margin-width
)
143 ("margin-top" margin-width
)
144 ("max-height" length percentage
"none")
145 ("max-width" length percentage
"none")
146 ("min-height" length percentage
)
147 ("min-width" length percentage
)
148 ("padding" padding-width
)
149 ("padding-bottom" padding-width
)
150 ("padding-left" padding-width
)
151 ("padding-right" padding-width
)
152 ("padding-top" padding-width
)
153 ("page-break-after" "auto" "always" "avoid" "left" "right")
154 ("page-break-before" "auto" "always" "avoid" "left" "right")
155 ("page-break-inside" "avoid" "auto")
156 ("pause" time percentage
)
157 ("pause-after" time percentage
)
158 ("pause-before" time percentage
)
159 ("pitch" frequency
"x-low" "low" "medium" "high" "x-high")
160 ("pitch-range" number
)
161 ("play-during" uri
"mix" "repeat" "auto" "none")
162 ("position" "static" "relative" "absolute" "fixed")
163 ("quotes" string
"none")
165 ("right" length percentage
"auto")
166 ("speak" "normal" "none" "spell-out")
167 ("speak-header" "once" "always")
168 ("speak-numeral" "digits" "continuous")
169 ("speak-punctuation" "code" "none")
170 ("speech-rate" number
"x-slow" "slow" "medium" "fast" "x-fast"
173 ("table-layout" "auto" "fixed")
174 ("top" length percentage
"auto")
175 ("unicode-bidi" "normal" "embed" "bidi-override")
176 ("vertical-align" "baseline" "sub" "super" "top" "text-top"
177 "middle" "bottom" "text-bottom" percentage length
)
178 ("visibility" "visible" "hidden" "collapse")
179 ("voice-family" specific-voice generic-voice specific-voice
181 ("volume" number percentage
"silent" "x-soft" "soft" "medium"
183 ("width" length percentage
"auto")
184 ("z-index" "auto" integer
)
187 ;; (http://www.w3.org/TR/css3-animations/#property-index)
188 ("animation" single-animation-name time single-timing-function
189 single-animation-iteration-count single-animation-direction
190 single-animation-fill-mode single-animation-play-state
)
191 ("animation-delay" time
)
192 ("animation-direction" single-animation-direction
)
193 ("animation-duration" time
)
194 ("animation-fill-mode" single-animation-fill-mode
)
195 ("animation-iteration-count" single-animation-iteration-count
)
196 ("animation-name" single-animation-name
)
197 ("animation-play-state" single-animation-play-state
)
198 ("animation-timing-function" single-timing-function
)
200 ;; CSS Backgrounds and Borders Module Level 3
201 ;; (http://www.w3.org/TR/css3-background/#property-index)
202 ("background" bg-layer final-bg-layer
)
203 ("background-attachment" attachment
)
204 ("background-clip" box
)
205 ("background-color" color
)
206 ("background-image" bg-image
)
207 ("background-origin" box
)
208 ("background-position" position
)
209 ("background-repeat" repeat-style
)
210 ("background-size" bg-size
)
211 ("border" line-width line-style color
)
212 ("border-bottom" line-width line-style color
)
213 ("border-bottom-color" color
)
214 ("border-bottom-left-radius" length percentage
)
215 ("border-bottom-right-radius" length percentage
)
216 ("border-bottom-style" line-style
)
217 ("border-bottom-width" line-width
)
218 ("border-color" color
)
219 ("border-image" border-image-source border-image-slice
220 border-image-width border-image-outset border-image-repeat
)
221 ("border-image-outset" length number
)
222 ("border-image-repeat" "stretch" "repeat" "round" "space")
223 ("border-image-slice" number percentage
"fill")
224 ("border-image-source" "none" image
)
225 ("border-image-width" length percentage number
"auto")
226 ("border-left" line-width line-style color
)
227 ("border-left-color" color
)
228 ("border-left-style" line-style
)
229 ("border-left-width" line-width
)
230 ("border-radius" length percentage
)
231 ("border-right" line-width line-style color
)
232 ("border-right-color" color
)
233 ("border-right-style" line-style
)
234 ("border-right-width" line-width
)
235 ("border-style" line-style
)
236 ("border-top" line-width line-style color
)
237 ("border-top-color" color
)
238 ("border-top-left-radius" length percentage
)
239 ("border-top-right-radius" length percentage
)
240 ("border-top-style" line-style
)
241 ("border-top-width" line-width
)
242 ("border-width" line-width
)
243 ("box-shadow" "none" shadow
)
245 ;; CSS Basic User Interface Module Level 3 (CSS3 UI)
246 ;; (http://www.w3.org/TR/css3-ui/#property-index)
247 ("box-sizing" "content-box" "border-box")
248 ("caret-color" "auto" color
)
249 ("cursor" uri x y
"auto" "default" "none" "context-menu" "help"
250 "pointer" "progress" "wait" "cell" "crosshair" "text"
251 "vertical-text" "alias" "copy" "move" "no-drop" "not-allowed"
252 "grab" "grabbing" "e-resize" "n-resize" "ne-resize" "nw-resize"
253 "s-resize" "se-resize" "sw-resize" "w-resize" "ew-resize"
254 "ns-resize" "nesw-resize" "nwse-resize" "col-resize" "row-resize"
255 "all-scroll" "zoom-in" "zoom-out")
256 ("nav-down" "auto" id
"current" "root" target-name
)
257 ("nav-left" "auto" id
"current" "root" target-name
)
258 ("nav-right" "auto" id
"current" "root" target-name
)
259 ("nav-up" "auto" id
"current" "root" target-name
)
260 ("outline" outline-color outline-style outline-width
)
261 ("outline-color" color
"invert")
262 ("outline-offset" length
)
263 ("outline-style" "auto" border-style
)
264 ("outline-width" border-width
)
265 ("resize" "none" "both" "horizontal" "vertical")
266 ("text-overflow" "clip" "ellipsis" string
)
268 ;; CSS Color Module Level 3
269 ;; (http://www.w3.org/TR/css3-color/#property)
271 ("opacity" alphavalue
)
273 ;; CSS Flexible Box Layout Module Level 1
274 ;; (http://www.w3.org/TR/css-flexbox-1/#property-index)
275 ("align-content" "flex-start" "flex-end" "center" "space-between"
276 "space-around" "stretch")
277 ("align-items" "flex-start" "flex-end" "center" "baseline"
279 ("align-self" "auto" "flex-start" "flex-end" "center" "baseline"
281 ("flex" "none" flex-grow flex-shrink flex-basis
)
282 ("flex-basis" "auto" "content" width
)
283 ("flex-direction" "row" "row-reverse" "column" "column-reverse")
284 ("flex-flow" flex-direction flex-wrap
)
286 ("flex-shrink" number
)
287 ("flex-wrap" "nowrap" "wrap" "wrap-reverse")
288 ("justify-content" "flex-start" "flex-end" "center"
289 "space-between" "space-around")
292 ;; CSS Fonts Module Level 3
293 ;; (http://www.w3.org/TR/css3-fonts/#property-index)
294 ("font" font-style font-variant-css21 font-weight font-stretch
295 font-size line-height font-family
"caption" "icon" "menu"
296 "message-box" "small-caption" "status-bar")
297 ("font-family" family-name generic-family
)
298 ("font-feature-settings" "normal" feature-tag-value
)
299 ("font-kerning" "auto" "normal" "none")
300 ("font-language-override" "normal" string
)
301 ("font-size" absolute-size relative-size length percentage
)
302 ("font-size-adjust" "none" number
)
303 ("font-stretch" "normal" "ultra-condensed" "extra-condensed"
304 "condensed" "semi-condensed" "semi-expanded" "expanded"
305 "extra-expanded" "ultra-expanded")
306 ("font-style" "normal" "italic" "oblique")
307 ("font-synthesis" "none" "weight" "style")
308 ("font-variant" "normal" "none" common-lig-values
309 discretionary-lig-values historical-lig-values
310 contextual-alt-values
"stylistic()" "historical-forms"
311 "styleset()" "character-variant()" "swash()" "ornaments()"
312 "annotation()" "small-caps" "all-small-caps" "petite-caps"
313 "all-petite-caps" "unicase" "titling-caps" numeric-figure-values
314 numeric-spacing-values numeric-fraction-values
"ordinal"
315 "slashed-zero" east-asian-variant-values east-asian-width-values
317 ("font-variant-alternates" "normal" "stylistic()"
318 "historical-forms" "styleset()" "character-variant()" "swash()"
319 "ornaments()" "annotation()")
320 ("font-variant-caps" "normal" "small-caps" "all-small-caps"
321 "petite-caps" "all-petite-caps" "unicase" "titling-caps")
322 ("font-variant-east-asian" "normal" east-asian-variant-values
323 east-asian-width-values
"ruby")
324 ("font-variant-ligatures" "normal" "none" common-lig-values
325 discretionary-lig-values historical-lig-values
326 contextual-alt-values
)
327 ("font-variant-numeric" "normal" numeric-figure-values
328 numeric-spacing-values numeric-fraction-values
"ordinal"
330 ("font-variant-position" "normal" "sub" "super")
331 ("font-weight" "normal" "bold" "bolder" "lighter" "100" "200"
332 "300" "400" "500" "600" "700" "800" "900")
334 ;; CSS Fragmentation Module Level 3
335 ;; (https://www.w3.org/TR/css-break-3/#property-index)
336 ("box-decoration-break" "slice" "clone")
337 ("break-after" "auto" "avoid" "avoid-page" "page" "left" "right"
338 "recto" "verso" "avoid-column" "column" "avoid-region" "region")
339 ("break-before" "auto" "avoid" "avoid-page" "page" "left" "right"
340 "recto" "verso" "avoid-column" "column" "avoid-region" "region")
341 ("break-inside" "auto" "avoid" "avoid-page" "avoid-column"
346 ;; CSS Multi-column Layout Module
347 ;; (https://www.w3.org/TR/css3-multicol/#property-index)
348 ;; "break-after", "break-before", and "break-inside" are left out
349 ;; below, because they're already included in CSS Fragmentation
351 ("column-count" integer
"auto")
352 ("column-fill" "auto" "balance")
353 ("column-gap" length
"normal")
354 ("column-rule" column-rule-width column-rule-style
355 column-rule-color
"transparent")
356 ("column-rule-color" color
)
357 ("column-rule-style" border-style
)
358 ("column-rule-width" border-width
)
359 ("column-span" "none" "all")
360 ("column-width" length
"auto")
361 ("columns" column-width column-count
)
363 ;; CSS Overflow Module Level 3
364 ;; (http://www.w3.org/TR/css-overflow-3/#property-index)
365 ("max-lines" "none" integer
)
366 ("overflow" "visible" "hidden" "scroll" "auto" "paged-x" "paged-y"
367 "paged-x-controls" "paged-y-controls" "fragments")
368 ("overflow-x" "visible" "hidden" "scroll" "auto" "paged-x"
369 "paged-y" "paged-x-controls" "paged-y-controls" "fragments")
370 ("overflow-y" "visible" "hidden" "scroll" "auto" "paged-x"
371 "paged-y" "paged-x-controls" "paged-y-controls" "fragments")
373 ;; CSS Text Decoration Module Level 3
374 ;; (http://dev.w3.org/csswg/css-text-decor-3/#property-index)
375 ("text-decoration" text-decoration-line text-decoration-style
376 text-decoration-color
)
377 ("text-decoration-color" color
)
378 ("text-decoration-line" "none" "underline" "overline"
379 "line-through" "blink")
380 ("text-decoration-skip" "none" "objects" "spaces" "ink" "edges"
382 ("text-decoration-style" "solid" "double" "dotted" "dashed"
384 ("text-emphasis" text-emphasis-style text-emphasis-color
)
385 ("text-emphasis-color" color
)
386 ("text-emphasis-position" "over" "under" "right" "left")
387 ("text-emphasis-style" "none" "filled" "open" "dot" "circle"
388 "double-circle" "triangle" "sesame" string
)
389 ("text-shadow" "none" length color
)
390 ("text-underline-position" "auto" "under" "left" "right")
392 ;; CSS Text Module Level 3
393 ;; (http://www.w3.org/TR/css3-text/#property-index)
394 ("hanging-punctuation" "none" "first" "force-end" "allow-end"
396 ("hyphens" "none" "manual" "auto")
397 ("letter-spacing" "normal" length
)
398 ("line-break" "auto" "loose" "normal" "strict")
399 ("overflow-wrap" "normal" "break-word")
400 ("tab-size" integer length
)
401 ("text-align" "start" "end" "left" "right" "center" "justify"
403 ("text-align-last" "auto" "start" "end" "left" "right" "center"
405 ("text-indent" length percentage
)
406 ("text-justify" "auto" "none" "inter-word" "distribute")
407 ("text-transform" "none" "capitalize" "uppercase" "lowercase"
409 ("white-space" "normal" "pre" "nowrap" "pre-wrap" "pre-line")
410 ("word-break" "normal" "keep-all" "break-all")
411 ("word-spacing" "normal" length percentage
)
412 ("word-wrap" "normal" "break-word")
414 ;; CSS Transforms Module Level 1
415 ;; (http://www.w3.org/TR/css3-2d-transforms/#property-index)
416 ("backface-visibility" "visible" "hidden")
417 ("perspective" "none" length
)
418 ("perspective-origin" "left" "center" "right" "top" "bottom"
420 ("transform" "none" transform-list
)
421 ("transform-origin" "left" "center" "right" "top" "bottom"
423 ("transform-style" "flat" "preserve-3d")
426 ;; (http://www.w3.org/TR/css3-transitions/#property-index)
427 ("transition" single-transition
)
428 ("transition-delay" time
)
429 ("transition-duration" time
)
430 ("transition-property" "none" single-transition-property
"all")
431 ("transition-timing-function" single-transition-timing-function
)
433 ;; CSS Will Change Module Level 1
434 ;; (https://www.w3.org/TR/css-will-change-1/#property-index)
435 ("will-change" "auto" animateable-feature
)
437 ;; Filter Effects Module Level 1
438 ;; (http://www.w3.org/TR/filter-effects/#property-index)
439 ("color-interpolation-filters" "auto" "sRGB" "linearRGB")
440 ("filter" "none" filter-function-list
)
441 ("flood-color" color
)
442 ("flood-opacity" number percentage
)
443 ("lighting-color" color
))
444 "Identifiers for properties and their possible values.
445 The CAR of each entry is the name of a property, while the CDR is
446 a list of possible values for that property. String values in
447 the CDRs represent literal values, while symbols represent one of
448 the value classes found in `css-value-class-alist'. If a symbol
449 is not found in `css-value-class-alist', it's interpreted as a
450 reference back to one of the properties in this list. Some
451 symbols, such as `number' or `identifier', don't produce any
452 further value candidates, since that list would be infinite.")
454 (defconst css-property-ids
455 (mapcar #'car css-property-alist
)
456 "Identifiers for properties.")
458 (defconst css-value-class-alist
460 "xx-small" "x-small" "small" "medium" "large" "x-large"
464 (animateable-feature "scroll-position" "contents" custom-ident
)
465 (attachment "scroll" "fixed" "local")
466 (bg-image image
"none")
467 (bg-layer bg-image position repeat-style attachment box
)
468 (bg-size length percentage
"auto" "cover" "contain")
469 (box "border-box" "padding-box" "content-box")
471 "rgb()" "rgba()" "hsl()" "hsla()" named-color
"transparent"
473 (common-lig-values "common-ligatures" "no-common-ligatures")
474 (contextual-alt-values "contextual" "no-contextual")
475 (counter "counter()" "counters()")
476 (discretionary-lig-values
477 "discretionary-ligatures" "no-discretionary-ligatures")
478 (east-asian-variant-values
479 "jis78" "jis83" "jis90" "jis04" "simplified" "traditional")
480 (east-asian-width-values "full-width" "proportional-width")
481 (family-name "Courier" "Helvetica" "Times")
482 (feature-tag-value string integer
"on" "off")
484 "blur()" "brightness()" "contrast()" "drop-shadow()"
485 "grayscale()" "hue-rotate()" "invert()" "opacity()" "sepia()"
487 (filter-function-list filter-function uri
)
489 bg-image position repeat-style attachment box color
)
490 (font-variant-css21 "normal" "small-caps")
493 "serif" "sans-serif" "cursive" "fantasy" "monospace")
494 (generic-voice "male" "female" "child")
496 linear-gradient radial-gradient repeating-linear-gradient
497 repeating-radial-gradient
)
498 (historical-lig-values
499 "historical-ligatures" "no-historical-ligatures")
500 (image uri image-list element-reference gradient
)
501 (image-list "image()")
503 (length "calc()" number
)
504 (line-height "normal" number length percentage
)
506 "none" "hidden" "dotted" "dashed" "solid" "double" "groove"
507 "ridge" "inset" "outset")
508 (line-width length
"thin" "medium" "thick")
509 (linear-gradient "linear-gradient()")
510 (margin-width "auto" length percentage
)
512 "aliceblue" "antiquewhite" "aqua" "aquamarine" "azure" "beige"
513 "bisque" "black" "blanchedalmond" "blue" "blueviolet" "brown"
514 "burlywood" "cadetblue" "chartreuse" "chocolate" "coral"
515 "cornflowerblue" "cornsilk" "crimson" "cyan" "darkblue"
516 "darkcyan" "darkgoldenrod" "darkgray" "darkgreen" "darkkhaki"
517 "darkmagenta" "darkolivegreen" "darkorange" "darkorchid"
518 "darkred" "darksalmon" "darkseagreen" "darkslateblue"
519 "darkslategray" "darkturquoise" "darkviolet" "deeppink"
520 "deepskyblue" "dimgray" "dodgerblue" "firebrick" "floralwhite"
521 "forestgreen" "fuchsia" "gainsboro" "ghostwhite" "gold"
522 "goldenrod" "gray" "green" "greenyellow" "honeydew" "hotpink"
523 "indianred" "indigo" "ivory" "khaki" "lavender" "lavenderblush"
524 "lawngreen" "lemonchiffon" "lightblue" "lightcoral" "lightcyan"
525 "lightgoldenrodyellow" "lightgray" "lightgreen" "lightpink"
526 "lightsalmon" "lightseagreen" "lightskyblue" "lightslategray"
527 "lightsteelblue" "lightyellow" "lime" "limegreen" "linen"
528 "magenta" "maroon" "mediumaquamarine" "mediumblue" "mediumorchid"
529 "mediumpurple" "mediumseagreen" "mediumslateblue"
530 "mediumspringgreen" "mediumturquoise" "mediumvioletred"
531 "midnightblue" "mintcream" "mistyrose" "moccasin" "navajowhite"
532 "navy" "oldlace" "olive" "olivedrab" "orange" "orangered"
533 "orchid" "palegoldenrod" "palegreen" "paleturquoise"
534 "palevioletred" "papayawhip" "peachpuff" "peru" "pink" "plum"
535 "powderblue" "purple" "rebeccapurple" "red" "rosybrown"
536 "royalblue" "saddlebrown" "salmon" "sandybrown" "seagreen"
537 "seashell" "sienna" "silver" "skyblue" "slateblue" "slategray"
538 "snow" "springgreen" "steelblue" "tan" "teal" "thistle" "tomato"
539 "turquoise" "violet" "wheat" "white" "whitesmoke" "yellow"
542 (numeric-figure-values "lining-nums" "oldstyle-nums")
543 (numeric-fraction-values "diagonal-fractions" "stacked-fractions")
544 (numeric-spacing-values "proportional-nums" "tabular-nums")
545 (padding-width length percentage
)
547 "left" "center" "right" "top" "bottom" percentage length
)
548 (radial-gradient "radial-gradient()")
549 (relative-size "larger" "smaller")
551 "repeat-x" "repeat-y" "repeat" "space" "round" "no-repeat")
552 (repeating-linear-gradient "repeating-linear-gradient()")
553 (repeating-radial-gradient "repeating-radial-gradient()")
554 (shadow "inset" length color
)
556 (single-animation-direction
557 "normal" "reverse" "alternate" "alternate-reverse")
558 (single-animation-fill-mode "none" "forwards" "backwards" "both")
559 (single-animation-iteration-count "infinite" number
)
560 (single-animation-name "none" identifier
)
561 (single-animation-play-state "running" "paused")
562 (single-timing-function single-transition-timing-function
)
564 "none" single-transition-property time
565 single-transition-timing-function
)
566 (single-transition-property "all" identifier
)
567 (single-transition-timing-function
568 "ease" "linear" "ease-in" "ease-out" "ease-in-out" "step-start"
569 "step-end" "steps()" "cubic-bezier()")
570 (specific-voice identifier
)
574 "matrix()" "translate()" "translateX()" "translateY()" "scale()"
575 "scaleX()" "scaleY()" "rotate()" "skew()" "skewX()" "skewY()"
576 "matrix3d()" "translate3d()" "translateZ()" "scale3d()"
577 "scaleZ()" "rotate3d()" "rotateX()" "rotateY()" "rotateZ()"
580 (width length percentage
"auto")
583 "Property value classes and their values.
584 The format is similar to that of `css-property-alist', except
585 that the CARs aren't actual CSS properties, but rather a name for
586 a class of values, and that symbols in the CDRs always refer to
587 other entries in this list, not to properties.
589 The following classes have been left out above because they
590 cannot be completed sensibly: `custom-ident',
591 `element-reference', `id', `identifier', `percentage', and
594 (defcustom css-electric-keys
'(?\
} ?\
;) ;; '()
595 "Self inserting keys which should trigger re-indentation."
597 :type
'(repeat character
)
598 :options
'((?\
} ?\
;))
601 (defvar css-mode-syntax-table
602 (let ((st (make-syntax-table)))
604 (modify-syntax-entry ?
/ ". 14" st
)
605 (modify-syntax-entry ?
* ". 23b" st
)
607 (modify-syntax-entry ?
\" "\"" st
)
608 (modify-syntax-entry ?
\' "\"" st
)
610 (modify-syntax-entry ?\
{ "(}" st
)
611 (modify-syntax-entry ?\
} "){" st
)
612 ;; Args in url(...) thingies and other "function calls".
613 (modify-syntax-entry ?\
( "()" st
)
614 (modify-syntax-entry ?\
) ")(" st
)
615 ;; To match attributes in selectors.
616 (modify-syntax-entry ?\
[ "(]" st
)
617 (modify-syntax-entry ?\
] ")[" st
)
618 ;; Special chars that sometimes come at the beginning of words.
619 (modify-syntax-entry ?
@ "'" st
)
620 ;; (modify-syntax-entry ?: "'" st)
621 (modify-syntax-entry ?
# "'" st
)
622 ;; Distinction between words and symbols.
623 (modify-syntax-entry ?-
"_" st
)
627 (let ((map (make-sparse-keymap)))
628 (define-key map
[remap info-lookup-symbol
] 'css-lookup-symbol
)
630 "Keymap used in `css-mode'.")
633 (defconst css--uri-re
635 "url\\((\\)[[:space:]]*\\(?:\\\\.\\|[^()[:space:]\n'\"]\\)+"
636 "[[:space:]]*\\()\\)")))
638 (defconst css-syntax-propertize-function
639 (syntax-propertize-rules
640 (css--uri-re (1 "|") (2 "|"))))
642 (defconst css-escapes-re
643 "\\\\\\(?:[^\000-\037\177]\\|[0-9a-fA-F]+[ \n\t\r\f]?\\)")
644 (defconst css-nmchar-re
(concat "\\(?:[-[:alnum:]]\\|" css-escapes-re
"\\)"))
645 (defconst css-nmstart-re
(concat "\\(?:[[:alpha:]]\\|" css-escapes-re
"\\)"))
646 (defconst css-ident-re
;; (concat css-nmstart-re css-nmchar-re "*")
647 ;; Apparently, "at rules" names can start with a dash, e.g. @-moz-keyframes.
648 (concat css-nmchar-re
"+"))
649 (defconst css-proprietary-nmstart-re
;; Vendor-specific properties.
650 (concat "[-_]" (regexp-opt '("ms" "moz" "o" "khtml" "webkit")) "-"))
651 (defconst css-name-re
(concat css-nmchar-re
"+"))
653 (defconst scss--hash-re
"#\\(?:{[$-_[:alnum:]]+}\\|[[:alnum:]]+\\)")
655 (defface css-selector
'((t :inherit font-lock-function-name-face
))
656 "Face to use for selectors."
658 (defface css-property
'((t :inherit font-lock-variable-name-face
))
659 "Face to use for properties."
661 (defface css-proprietary-property
'((t :inherit
(css-property italic
)))
662 "Face to use for vendor-specific properties.")
664 (defun css--font-lock-keywords (&optional sassy
)
665 `((,(concat "!\\s-*" (regexp-opt css--bang-ids
))
666 (0 font-lock-builtin-face
))
667 ;; Atrules keywords. IDs not in css-at-ids are valid (ignored).
668 ;; In fact the regexp should probably be
669 ;; (,(concat "\\(@" css-ident-re "\\)\\([ \t\n][^;{]*\\)[;{]")
670 ;; (1 font-lock-builtin-face))
671 ;; Since "An at-rule consists of everything up to and including the next
672 ;; semicolon (;) or the next block, whichever comes first."
673 (,(concat "@" css-ident-re
) (0 font-lock-builtin-face
))
675 (,(concat "--" css-ident-re
) (0 font-lock-variable-name-face
))
677 ;; Allow plain ":root" as a selector.
678 ("^[ \t]*\\(:root\\)\\(?:[\n \t]*\\)*{" (1 'css-selector keep
))
679 ;; FIXME: attribute selectors don't work well because they may contain
680 ;; strings which have already been highlighted as f-l-string-face and
681 ;; thus prevent this highlighting from being applied (actually now that
682 ;; I use `keep' this should work better). But really the part of the
683 ;; selector between [...] should simply not be highlighted.
687 ;; We don't allow / as first char, so as not to
688 ;; take a comment as the beginning of a selector.
689 "[^@/:{}() \t\n][^:{}()]+"
690 ;; Same as for non-sassy except we do want to allow { and }
691 ;; chars in selectors in the case of #{$foo}
692 ;; variable interpolation!
693 (concat "\\(?:" scss--hash-re
694 "\\|[^@/:{}() \t\n#]\\)"
695 "[^:{}()#]*\\(?:" scss--hash-re
"[^:{}()#]*\\)*"))
696 ;; Even though pseudo-elements should be prefixed by ::, a
697 ;; single colon is accepted for backward compatibility.
698 "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
699 css-pseudo-element-ids
)
701 "\\|\\::" (regexp-opt css-pseudo-element-ids t
) "\\)"
705 (concat "[^:{}()\n#]*\\(?:" scss--hash-re
"[^:{}()\n#]*\\)*"))
707 "\\)\\(?:\n[ \t]*\\)*{")
708 (1 'css-selector keep
))
709 ;; In the above rule, we allow the open-brace to be on some subsequent
710 ;; line. This will only work if we properly mark the intervening text
711 ;; as being part of a multiline element (and even then, this only
712 ;; ensures proper refontification, but not proper discovery).
713 ("^[ \t]*{" (0 (save-excursion
714 (goto-char (match-beginning 0))
715 (skip-chars-backward " \n\t")
716 (put-text-property (point) (match-end 0)
717 'font-lock-multiline t
)
720 ;; Properties. Again, we don't limit ourselves to css-property-ids.
721 (,(concat "\\(?:[{;]\\|^\\)[ \t]*\\("
722 "\\(?:\\(" css-proprietary-nmstart-re
"\\)\\|"
723 css-nmstart-re
"\\)" css-nmchar-re
"*"
725 (1 (if (match-end 2) 'css-proprietary-property
'css-property
)))
726 ;; Make sure the parens in a url(...) expression receive the
727 ;; default face. This is done because the parens may sometimes
728 ;; receive generic string delimiter syntax (see
729 ;; `css-syntax-propertize-function').
731 (1 'default t
) (2 'default t
))))
733 (defvar css-font-lock-keywords
(css--font-lock-keywords))
735 (defvar css-font-lock-defaults
736 '(css-font-lock-keywords nil t
))
738 (defcustom css-indent-offset
4
739 "Basic size of one indentation step."
744 (defconst css-smie-grammar
748 ;; Colons that belong to a CSS property. These get a higher
749 ;; precedence than other colons, such as colons in selectors,
750 ;; which are represented by a plain ":" token.
755 (defun css--colon-inside-selector-p ()
756 "Return t if point looks to be inside a CSS selector.
757 This function is intended to be good enough to help SMIE during
758 tokenization, but should not be regarded as a reliable function
759 for determining whether point is within a selector."
761 (re-search-forward "[{};)]" nil t
)
762 (eq (char-before) ?\
{)))
764 (defun css--colon-inside-funcall ()
765 "Return t if point is inside a function call."
766 (when-let (opening-paren-pos (nth 1 (syntax-ppss)))
768 (goto-char opening-paren-pos
)
769 (eq (char-after) ?\
())))
771 (defun css-smie--forward-token ()
773 ((and (eq (char-before) ?\
})
774 (scss-smie--not-interpolation-p)
775 ;; FIXME: If the next char is not whitespace, what should we do?
776 (or (memq (char-after) '(?\s ?
\t ?
\n))
777 (looking-at comment-start-skip
)))
778 (if (memq (char-after) '(?\s ?
\t ?
\n))
779 (forward-char 1) (forward-comment 1))
781 ((progn (forward-comment (point-max))
782 (looking-at "[;,:]"))
784 (if (equal (match-string 0) ":")
785 (if (or (css--colon-inside-selector-p)
786 (css--colon-inside-funcall))
790 (t (smie-default-forward-token))))
792 (defun css-smie--backward-token ()
794 (forward-comment (- (point)))
796 ;; FIXME: If the next char is not whitespace, what should we do?
797 ((and (eq (char-before) ?\
}) (scss-smie--not-interpolation-p)
798 (> pos
(point))) ";")
799 ((memq (char-before) '(?\
; ?\, ?\:))
801 (if (eq (char-after) ?\
:)
802 (if (or (css--colon-inside-selector-p)
803 (css--colon-inside-funcall))
806 (string (char-after))))
807 (t (smie-default-backward-token)))))
809 (defun css-smie-rules (kind token
)
810 (pcase (cons kind token
)
811 (`(:elem . basic
) css-indent-offset
)
813 (`(:list-intro .
,(or `";" `"")) t
) ;"" stands for BOB (bug#15467).
815 (when (or (smie-rule-hanging-p) (smie-rule-bolp))
816 (smie-backward-sexp ";")
817 (smie-indent-virtual)))
818 (`(:before .
,(or "{" "("))
819 (if (smie-rule-hanging-p) (smie-rule-parent 0)))))
823 (defun css--complete-property ()
824 "Complete property at point."
827 (skip-chars-backward "-[:alnum:]")
828 (let ((start (point)))
829 (skip-chars-backward " \t\r\n")
830 (when (memq (char-before) '(?\
{ ?\
;))
831 (list start pos css-property-ids
))))))
833 (defun css--complete-bang-rule ()
834 "Complete bang-rule at point."
837 (skip-chars-backward "-[:alnum:]")
838 (when (eq (char-before) ?\
!)
839 (list (point) pos css--bang-ids
)))))
841 (defun css--complete-pseudo-element-or-class ()
842 "Complete pseudo-element or pseudo-class at point."
845 (skip-chars-backward "-[:alnum:]")
846 (when (eq (char-before) ?\
:)
848 (if (eq (char-before (- (point) 1)) ?\
:)
849 css-pseudo-element-ids
850 css-pseudo-class-ids
))))))
852 (defun css--complete-at-rule ()
853 "Complete at-rule (statement beginning with `@') at point."
856 (skip-chars-backward "-[:alnum:]")
857 (when (eq (char-before) ?\
@)
858 (list (point) pos css--at-ids
)))))
860 (defvar css--property-value-cache
861 (make-hash-table :test
'equal
:size
(length css-property-alist
))
862 "Cache of previously completed property values.")
864 (defun css--value-class-lookup (value-class)
865 "Return a list of value completion candidates for VALUE-CLASS.
866 Completion candidates are looked up in `css-value-class-alist' by
867 the symbol VALUE-CLASS."
873 (css--value-class-lookup value
)))
874 (cdr (assq value-class css-value-class-alist
)))))
876 (defun css--property-values (property)
877 "Return a list of value completion candidates for PROPERTY.
878 Completion candidates are looked up in `css-property-alist' by
879 the string PROPERTY."
880 (or (gethash property css--property-value-cache
)
887 (or (css--value-class-lookup value
)
888 (css--property-values (symbol-name value
)))))
889 (cdr (assoc property css-property-alist
))))))
890 (puthash property values css--property-value-cache
))))
892 (defun css--complete-property-value ()
893 "Complete property value at point."
896 (re-search-backward ":[^/]" (line-beginning-position) t
)
897 (let ((property-end (point)))
898 (skip-chars-backward "-[:alnum:]")
899 (let ((property (buffer-substring (point) property-end
)))
900 (car (member property css-property-ids
)))))))
904 (skip-chars-backward "[:graph:]")
906 (append '("inherit" "initial" "unset")
907 (css--property-values property
))))))))
909 (defvar css--html-tags
(mapcar #'car html-tag-alist
)
911 Used to provide completion of HTML tags in selectors.")
913 (defvar css--nested-selectors-allowed nil
914 "Non-nil if nested selectors are allowed in the current mode.")
915 (make-variable-buffer-local 'css--nested-selectors-allowed
)
917 (defvar css-class-list-function
#'ignore
918 "Called to provide completions of class names.
919 This can be bound by buffers that are able to suggest class name
920 completions, such as HTML mode buffers.")
922 (defvar css-id-list-function
#'ignore
923 "Called to provide completions of IDs.
924 This can be bound by buffers that are able to suggest ID
925 completions, such as HTML mode buffers.")
927 (defun css--foreign-completions (extractor)
928 "Return a list of completions provided by other buffers.
929 EXTRACTOR should be the name of a function that may be defined in
930 one or more buffers. In each of the buffers where EXTRACTOR is
931 defined, EXTRACTOR is called and the results are accumulated into
932 a list of completions."
936 (with-current-buffer buf
937 (funcall (symbol-value extractor
))))
940 (defun css--complete-selector ()
941 "Complete part of a CSS selector at point."
942 (when (or (= (nth 0 (syntax-ppss)) 0) css--nested-selectors-allowed
)
945 (skip-chars-backward "-[:alnum:]")
946 (let ((start-char (char-before)))
949 (completion-table-dynamic
953 (css--foreign-completions 'css-class-list-function
))
955 (css--foreign-completions 'css-id-list-function
))
956 (t css--html-tags
))))))))))
958 (defun css-completion-at-point ()
959 "Complete current symbol at point.
960 Currently supports completion of CSS properties, property values,
961 pseudo-elements, pseudo-classes, at-rules, and bang-rules."
962 (or (css--complete-bang-rule)
963 (css--complete-property-value)
964 (css--complete-pseudo-element-or-class)
965 (css--complete-at-rule)
966 (seq-let (prop-beg prop-end prop-table
) (css--complete-property)
967 (seq-let (sel-beg sel-end sel-table
) (css--complete-selector)
968 (when (or prop-table sel-table
)
969 ;; FIXME: If both prop-table and sel-table are set but
970 ;; prop-beg/prop-end is different from sel-beg/sel-end
971 ;; we have a problem!
973 (list prop-beg prop-end
)
974 (list sel-beg sel-end
))
975 ,(completion-table-merge prop-table sel-table
)
977 ,(lambda (string status
)
978 (and (eq status
'finished
)
980 (test-completion string prop-table
)
982 (test-completion string sel-table
)))
983 (progn (insert ": ;")
984 (forward-char -
1))))))))))
987 (define-derived-mode css-mode prog-mode
"CSS"
988 "Major mode to edit Cascading Style Sheets."
989 (setq-local font-lock-defaults css-font-lock-defaults
)
990 (setq-local comment-start
"/*")
991 (setq-local comment-start-skip
"/\\*+[ \t]*")
992 (setq-local comment-end
"*/")
993 (setq-local comment-end-skip
"[ \t]*\\*+/")
994 (setq-local syntax-propertize-function
995 css-syntax-propertize-function
)
996 (setq-local fill-paragraph-function
#'css-fill-paragraph
)
997 (setq-local adaptive-fill-function
#'css-adaptive-fill
)
998 (setq-local add-log-current-defun-function
#'css-current-defun-name
)
999 (smie-setup css-smie-grammar
#'css-smie-rules
1000 :forward-token
#'css-smie--forward-token
1001 :backward-token
#'css-smie--backward-token
)
1002 (setq-local electric-indent-chars
1003 (append css-electric-keys electric-indent-chars
))
1004 (add-hook 'completion-at-point-functions
1005 #'css-completion-at-point nil
'local
))
1007 (defvar comment-continue
)
1009 (defun css-fill-paragraph (&optional justify
)
1011 ;; Fill succeeding comment when invoked right before a multi-line
1013 (when (save-excursion
1015 (comment-search-forward (point-at-eol) t
))
1016 (goto-char (match-end 0)))
1017 (let ((ppss (syntax-ppss))
1018 (eol (line-end-position)))
1022 (goto-char (nth 8 ppss
))
1025 (setq eol
(point)))))
1026 ;; Filling inside a comment whose comment-end marker is not \n.
1027 ;; This code is meant to be generic, so that it works not only for
1028 ;; css-mode but for all modes.
1030 (narrow-to-region (nth 8 ppss
) eol
)
1031 (comment-normalize-vars) ;Will define comment-continue.
1032 (let ((fill-paragraph-function nil
)
1034 (if (and comment-continue
1035 (string-match "[^ \t]" comment-continue
))
1036 (concat "\\(?:[ \t]*\\(?:"
1037 (regexp-quote comment-continue
) "\\|"
1038 comment-start-skip
"\\|"
1039 comment-end-skip
"\\)\\)?"
1040 "\\(?:" paragraph-separate
"\\)")
1041 paragraph-separate
))
1043 (if (and comment-continue
1044 (string-match "[^ \t]" comment-continue
))
1045 (concat "\\(?:[ \t]*" (regexp-quote comment-continue
)
1046 "\\)?\\(?:" paragraph-start
"\\)")
1048 (fill-paragraph justify
)
1049 ;; Don't try filling again.
1052 ((and (null (nth 8 ppss
))
1056 (when (<= (point) eol
)
1057 (setq ppss
(syntax-ppss)))))))
1058 (goto-char (nth 1 ppss
))
1059 (let ((end (save-excursion
1060 (ignore-errors (forward-sexp 1) (copy-marker (point) t
)))))
1062 (while (re-search-forward "[{;}]" end t
)
1064 ;; This is a false positive inside a string or comment.
1065 ((nth 8 (syntax-ppss)) nil
)
1066 ;; This is a false positive when encountering an
1067 ;; interpolated variable (bug#19751).
1068 ((eq (char-before (- (point) 1)) ?
#) nil
)
1069 ((eq (char-before) ?\
})
1072 (skip-chars-backward " \t")
1073 (when (and (not (bolp))
1074 (scss-smie--not-interpolation-p))
1079 (setq eol
(line-end-position))
1080 (and (forward-comment 1)
1082 ;; A multi-line comment should be on its own line.
1083 (save-excursion (forward-comment -
1)
1084 (when (< (point) eol
)
1087 (if (< (point) eol
) (newline)))))
1088 (goto-char (nth 1 ppss
))
1089 (indent-region (line-beginning-position 2) end
)
1090 ;; Don't use the default filling code.
1093 (defun css-adaptive-fill ()
1094 (when (looking-at "[ \t]*/\\*[ \t]*")
1095 (let ((str (match-string 0)))
1096 (and (string-match "/\\*" str
)
1097 (replace-match " *" t t str
)))))
1099 (defun css-current-defun-name ()
1100 "Return the name of the CSS section at point, or nil."
1102 (let ((max (max (point-min) (- (point) 1600)))) ; approx 20 lines back
1103 (when (search-backward "{" max t
)
1104 (skip-chars-backward " \t\r\n")
1106 (if (looking-at "^[ \t]*\\([^{\r\n]*[^ {\t\r\n]\\)")
1107 (match-string-no-properties 1))))))
1111 (defvar scss-mode-syntax-table
1112 (let ((st (make-syntax-table css-mode-syntax-table
)))
1113 (modify-syntax-entry ?
/ ". 124" st
)
1114 (modify-syntax-entry ?
\n ">" st
)
1115 ;; Variable names are prefixed by $.
1116 (modify-syntax-entry ?$
"'" st
)
1119 (defun scss-font-lock-keywords ()
1120 (append `((,(concat "$" css-ident-re
) (0 font-lock-variable-name-face
)))
1121 (css--font-lock-keywords 'sassy
)
1122 `((,(concat "@mixin[ \t]+\\(" css-ident-re
"\\)[ \t]*(")
1123 (1 font-lock-function-name-face
)))))
1125 (defun scss-smie--not-interpolation-p ()
1128 (or (zerop (skip-chars-backward "-[:alnum:]"))
1129 (not (looking-back "#{\\$" (- (point) 3))))))
1131 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.scss\\'" . scss-mode))
1133 (define-derived-mode scss-mode css-mode
"SCSS"
1134 "Major mode to edit \"Sassy CSS\" files."
1135 (setq-local comment-start
"// ")
1136 (setq-local comment-end
"")
1137 (setq-local comment-continue
" *")
1138 (setq-local comment-start-skip
"/[*/]+[ \t]*")
1139 (setq-local comment-end-skip
"[ \t]*\\(?:\n\\|\\*+/\\)")
1140 (setq-local css--at-ids
(append css-at-ids scss-at-ids
))
1141 (setq-local css--bang-ids
(append css-bang-ids scss-bang-ids
))
1142 (setq-local css--nested-selectors-allowed t
)
1143 (setq-local font-lock-defaults
1144 (list (scss-font-lock-keywords) nil t
)))
1148 (defvar css--mdn-lookup-history nil
)
1150 (defcustom css-lookup-url-format
1151 "https://developer.mozilla.org/en-US/docs/Web/CSS/%s?raw¯os"
1152 "Format for a URL where CSS documentation can be found.
1153 The format should include a single \"%s\" substitution.
1154 The name of the CSS property, @-id, pseudo-class, or pseudo-element
1155 to look up will be substituted there."
1160 (defun css--mdn-after-render ()
1161 (setf header-line-format nil
)
1162 (goto-char (point-min))
1163 (let ((window (get-buffer-window (current-buffer) 'visible
)))
1165 (when (re-search-forward "^Summary" nil
'move
)
1167 (set-window-start window
(point))))))
1169 (defconst css--mdn-symbol-regexp
1172 "\\(@" (regexp-opt css-at-ids
) "\\)"
1174 ;; ;; Known properties.
1175 (regexp-opt css-property-ids t
)
1178 "\\(:" (regexp-opt css-pseudo-class-ids
) "\\)"
1180 ;; Pseudo-elements with either one or two ":"s.
1181 "\\(::?" (regexp-opt css-pseudo-element-ids
) "\\)"
1183 "Regular expression to match the CSS symbol at point.")
1185 (defconst css--mdn-property-regexp
1186 (concat "\\_<" (regexp-opt css-property-ids t
) "\\s-*\\(?:\\=\\|:\\)")
1187 "Regular expression to match a CSS property.")
1189 (defconst css--mdn-completion-list
1192 (mapcar (lambda (atrule) (concat "@" atrule
)) css-at-ids
)
1194 (mapcar (lambda (class) (concat ":" class
)) css-pseudo-class-ids
)
1195 ;; Pseudo-elements with either one or two ":"s.
1196 (mapcar (lambda (elt) (concat ":" elt
)) css-pseudo-element-ids
)
1197 (mapcar (lambda (elt) (concat "::" elt
)) css-pseudo-element-ids
)
1200 "List of all symbols available for lookup via MDN.")
1202 (defun css--mdn-find-symbol ()
1203 "A helper for `css-lookup-symbol' that finds the symbol at point.
1204 Returns the symbol, a string, or nil if none found."
1206 ;; Skip any whitespace between the word and point.
1207 (skip-chars-backward "- \t")
1208 ;; Skip backward over a word.
1209 (skip-chars-backward "-[:alnum:]")
1210 ;; Now skip ":" or "@" to see if it's a pseudo-element or at-id.
1211 (skip-chars-backward "@:")
1212 (if (looking-at css--mdn-symbol-regexp
)
1213 (match-string-no-properties 0)
1214 (let ((bound (save-excursion
1217 (when (re-search-backward css--mdn-property-regexp bound t
)
1218 (match-string-no-properties 1))))))
1221 (defun css-lookup-symbol (symbol)
1222 "Display the CSS documentation for SYMBOL, as found on MDN.
1223 When this command is used interactively, it picks a default
1224 symbol based on the CSS text before point -- either an @-keyword,
1225 a property name, a pseudo-class, or a pseudo-element, depending
1226 on what is seen near point."
1229 (let* ((sym (css--mdn-find-symbol))
1230 (enable-recursive-minibuffers t
)
1231 (value (completing-read
1233 (format "Describe CSS symbol (default %s): " sym
)
1234 "Describe CSS symbol: ")
1235 css--mdn-completion-list nil nil nil
1236 'css--mdn-lookup-history sym
)))
1237 (if (equal value
"") sym value
))))
1239 ;; If we see a single-colon pseudo-element like ":after", turn it
1241 (when (and (eq (aref symbol
0) ?
:)
1242 (member (substring symbol
1) css-pseudo-element-ids
))
1243 (setq symbol
(concat ":" symbol
)))
1244 (let ((url (format css-lookup-url-format symbol
))
1245 (buffer (get-buffer-create "*MDN CSS*")))
1246 (save-selected-window
1247 ;; Make sure to display the buffer before calling `eww', as
1248 ;; that calls `pop-to-buffer-same-window'.
1249 (switch-to-buffer-other-window buffer
)
1250 (with-current-buffer buffer
1252 (add-hook 'eww-after-render-hook
#'css--mdn-after-render nil t
)
1256 ;;; css-mode.el ends here