]> code.delx.au - gnu-emacs/blob - lisp/textmodes/css-mode.el
Handle Bug#23186
[gnu-emacs] / lisp / textmodes / css-mode.el
1 ;;; css-mode.el --- Major mode to edit CSS files -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2006-2016 Free Software Foundation, Inc.
4
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
6 ;; Maintainer: Simen Heggestøyl <simenheg@gmail.com>
7 ;; Keywords: hypermedia
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24 ;;; Commentary:
25
26 ;; Yet another CSS mode.
27
28 ;;; Todo:
29
30 ;; - electric ; and }
31 ;; - filling code with auto-fill-mode
32 ;; - attribute value completion
33 ;; - fix font-lock errors with multi-line selectors
34
35 ;;; Code:
36
37 (defgroup css nil
38 "Cascading Style Sheets (CSS) editing mode."
39 :group 'languages)
40
41 (defconst css-pseudo-class-ids
42 '("active" "checked" "disabled" "empty" "enabled" "first"
43 "first-child" "first-of-type" "focus" "hover" "indeterminate" "lang"
44 "last-child" "last-of-type" "left" "link" "not" "nth-child"
45 "nth-last-child" "nth-last-of-type" "nth-of-type" "only-child"
46 "only-of-type" "right" "root" "target" "visited")
47 "Identifiers for pseudo-classes.")
48
49 (defconst css-pseudo-element-ids
50 '("after" "before" "first-letter" "first-line")
51 "Identifiers for pseudo-elements.")
52
53 (defconst css-at-ids
54 '("charset" "font-face" "import" "media" "namespace" "page")
55 "Identifiers that appear in the form @foo.")
56
57 (defconst css-bang-ids
58 '("important")
59 "Identifiers that appear in the form !foo.")
60
61 (defconst scss-bang-ids
62 '("default" "global" "optional")
63 "Additional identifiers that appear in the form !foo in SCSS.")
64
65 (defconst css-descriptor-ids
66 '("ascent" "baseline" "bbox" "cap-height" "centerline" "definition-src"
67 "descent" "font-family" "font-size" "font-stretch" "font-style"
68 "font-variant" "font-weight" "mathline" "panose-1" "slope" "src" "stemh"
69 "stemv" "topline" "unicode-range" "units-per-em" "widths" "x-height")
70 "Identifiers for font descriptors.")
71
72 (defconst css-media-ids
73 '("all" "aural" "bitmap" "continuous" "grid" "paged" "static" "tactile"
74 "visual")
75 "Identifiers for types of media.")
76
77 (defconst css-property-ids
78 '(;; CSS 2.1 properties (http://www.w3.org/TR/CSS21/propidx.html).
79 ;;
80 ;; Properties duplicated by any of the CSS3 modules below have
81 ;; been removed.
82 "azimuth" "border-collapse" "border-spacing" "bottom"
83 "caption-side" "clear" "clip" "content" "counter-increment"
84 "counter-reset" "cue" "cue-after" "cue-before" "direction" "display"
85 "elevation" "empty-cells" "float" "height" "left" "line-height"
86 "list-style" "list-style-image" "list-style-position"
87 "list-style-type" "margin" "margin-bottom" "margin-left"
88 "margin-right" "margin-top" "max-height" "max-width" "min-height"
89 "min-width" "orphans" "padding" "padding-bottom" "padding-left"
90 "padding-right" "padding-top" "page-break-after"
91 "page-break-before" "page-break-inside" "pause" "pause-after"
92 "pause-before" "pitch" "pitch-range" "play-during" "position"
93 "quotes" "richness" "right" "speak" "speak-header" "speak-numeral"
94 "speak-punctuation" "speech-rate" "stress" "table-layout" "top"
95 "unicode-bidi" "vertical-align" "visibility" "voice-family" "volume"
96 "widows" "width" "z-index"
97
98 ;; CSS Animations
99 ;; (http://www.w3.org/TR/css3-animations/#property-index)
100 "animation" "animation-delay" "animation-direction"
101 "animation-duration" "animation-fill-mode"
102 "animation-iteration-count" "animation-name"
103 "animation-play-state" "animation-timing-function"
104
105 ;; CSS Backgrounds and Borders Module Level 3
106 ;; (http://www.w3.org/TR/css3-background/#property-index)
107 "background" "background-attachment" "background-clip"
108 "background-color" "background-image" "background-origin"
109 "background-position" "background-repeat" "background-size"
110 "border" "border-bottom" "border-bottom-color"
111 "border-bottom-left-radius" "border-bottom-right-radius"
112 "border-bottom-style" "border-bottom-width" "border-color"
113 "border-image" "border-image-outset" "border-image-repeat"
114 "border-image-slice" "border-image-source" "border-image-width"
115 "border-left" "border-left-color" "border-left-style"
116 "border-left-width" "border-radius" "border-right"
117 "border-right-color" "border-right-style" "border-right-width"
118 "border-style" "border-top" "border-top-color"
119 "border-top-left-radius" "border-top-right-radius"
120 "border-top-style" "border-top-width" "border-width" "box-shadow"
121
122 ;; CSS Basic User Interface Module Level 3 (CSS3 UI)
123 ;; (http://www.w3.org/TR/css3-ui/#property-index)
124 "box-sizing" "caret-color" "cursor" "nav-down" "nav-left"
125 "nav-right" "nav-up" "outline" "outline-color" "outline-offset"
126 "outline-style" "outline-width" "resize" "text-overflow"
127
128 ;; CSS Color Module Level 3
129 ;; (http://www.w3.org/TR/css3-color/#property)
130 "color" "opacity"
131
132 ;; CSS Flexible Box Layout Module Level 1
133 ;; (http://www.w3.org/TR/css-flexbox-1/#property-index)
134 "align-content" "align-items" "align-self" "flex" "flex-basis"
135 "flex-direction" "flex-flow" "flex-grow" "flex-shrink" "flex-wrap"
136 "justify-content" "order"
137
138 ;; CSS Fonts Module Level 3
139 ;; (http://www.w3.org/TR/css3-fonts/#property-index)
140 "font" "font-family" "font-feature-settings" "font-kerning"
141 "font-language-override" "font-size" "font-size-adjust"
142 "font-stretch" "font-style" "font-synthesis" "font-variant"
143 "font-variant-alternates" "font-variant-caps"
144 "font-variant-east-asian" "font-variant-ligatures"
145 "font-variant-numeric" "font-variant-position" "font-weight"
146
147 ;; CSS Overflow Module Level 3
148 ;; (http://www.w3.org/TR/css-overflow-3/#property-index)
149 "max-lines" "overflow" "overflow-x" "overflow-y"
150
151 ;; CSS Text Decoration Module Level 3
152 ;; (http://dev.w3.org/csswg/css-text-decor-3/#property-index)
153 "text-decoration" "text-decoration-color" "text-decoration-line"
154 "text-decoration-skip" "text-decoration-style" "text-emphasis"
155 "text-emphasis-color" "text-emphasis-position" "text-emphasis-style"
156 "text-shadow" "text-underline-position"
157
158 ;; CSS Text Module Level 3
159 ;; (http://www.w3.org/TR/css3-text/#property-index)
160 "hanging-punctuation" "hyphens" "letter-spacing" "line-break"
161 "overflow-wrap" "tab-size" "text-align" "text-align-last"
162 "text-indent" "text-justify" "text-transform" "white-space"
163 "word-break" "word-spacing" "word-wrap"
164
165 ;; CSS Transforms Module Level 1
166 ;; (http://www.w3.org/TR/css3-2d-transforms/#property-index)
167 "backface-visibility" "perspective" "perspective-origin"
168 "transform" "transform-origin" "transform-style"
169
170 ;; CSS Transitions
171 ;; (http://www.w3.org/TR/css3-transitions/#property-index)
172 "transition" "transition-delay" "transition-duration"
173 "transition-property" "transition-timing-function"
174
175 ;; Filter Effects Module Level 1
176 ;; (http://www.w3.org/TR/filter-effects/#property-index)
177 "color-interpolation-filters" "filter" "flood-color"
178 "flood-opacity" "lighting-color")
179 "Identifiers for properties.")
180
181 (defcustom css-electric-keys '(?\} ?\;) ;; '()
182 "Self inserting keys which should trigger re-indentation."
183 :version "22.2"
184 :type '(repeat character)
185 :options '((?\} ?\;))
186 :group 'css)
187
188 (defvar css-mode-syntax-table
189 (let ((st (make-syntax-table)))
190 ;; C-style comments.
191 (modify-syntax-entry ?/ ". 14" st)
192 (modify-syntax-entry ?* ". 23b" st)
193 ;; Strings.
194 (modify-syntax-entry ?\" "\"" st)
195 (modify-syntax-entry ?\' "\"" st)
196 ;; Blocks.
197 (modify-syntax-entry ?\{ "(}" st)
198 (modify-syntax-entry ?\} "){" st)
199 ;; Args in url(...) thingies and other "function calls".
200 (modify-syntax-entry ?\( "()" st)
201 (modify-syntax-entry ?\) ")(" st)
202 ;; To match attributes in selectors.
203 (modify-syntax-entry ?\[ "(]" st)
204 (modify-syntax-entry ?\] ")[" st)
205 ;; Special chars that sometimes come at the beginning of words.
206 (modify-syntax-entry ?@ "'" st)
207 ;; (modify-syntax-entry ?: "'" st)
208 (modify-syntax-entry ?# "'" st)
209 ;; Distinction between words and symbols.
210 (modify-syntax-entry ?- "_" st)
211 st))
212
213 (eval-and-compile
214 (defconst css--uri-re
215 (concat
216 "url\\((\\)[[:space:]]*\\(?:\\\\.\\|[^()[:space:]\n'\"]\\)+"
217 "[[:space:]]*\\()\\)")))
218
219 (defconst css-syntax-propertize-function
220 (syntax-propertize-rules
221 (css--uri-re (1 "|") (2 "|"))))
222
223 (defconst css-escapes-re
224 "\\\\\\(?:[^\000-\037\177]\\|[0-9a-fA-F]+[ \n\t\r\f]?\\)")
225 (defconst css-nmchar-re (concat "\\(?:[-[:alnum:]]\\|" css-escapes-re "\\)"))
226 (defconst css-nmstart-re (concat "\\(?:[[:alpha:]]\\|" css-escapes-re "\\)"))
227 (defconst css-ident-re ;; (concat css-nmstart-re css-nmchar-re "*")
228 ;; Apparently, "at rules" names can start with a dash, e.g. @-moz-keyframes.
229 (concat css-nmchar-re "+"))
230 (defconst css-proprietary-nmstart-re ;; Vendor-specific properties.
231 (concat "[-_]" (regexp-opt '("ms" "moz" "o" "khtml" "webkit")) "-"))
232 (defconst css-name-re (concat css-nmchar-re "+"))
233
234 (defconst scss--hash-re "#\\(?:{[$-_[:alnum:]]+}\\|[[:alnum:]]+\\)")
235
236 (defface css-selector '((t :inherit font-lock-function-name-face))
237 "Face to use for selectors."
238 :group 'css)
239 (defface css-property '((t :inherit font-lock-variable-name-face))
240 "Face to use for properties."
241 :group 'css)
242 (defface css-proprietary-property '((t :inherit (css-property italic)))
243 "Face to use for vendor-specific properties.")
244
245 (defun css--font-lock-keywords (&optional sassy)
246 `((,(concat "!\\s-*"
247 (regexp-opt (append (if sassy scss-bang-ids)
248 css-bang-ids)))
249 (0 font-lock-builtin-face))
250 ;; Atrules keywords. IDs not in css-at-ids are valid (ignored).
251 ;; In fact the regexp should probably be
252 ;; (,(concat "\\(@" css-ident-re "\\)\\([ \t\n][^;{]*\\)[;{]")
253 ;; (1 font-lock-builtin-face))
254 ;; Since "An at-rule consists of everything up to and including the next
255 ;; semicolon (;) or the next block, whichever comes first."
256 (,(concat "@" css-ident-re) (0 font-lock-builtin-face))
257 ;; Variables.
258 (,(concat "--" css-ident-re) (0 font-lock-variable-name-face))
259 ;; Selectors.
260 ;; FIXME: attribute selectors don't work well because they may contain
261 ;; strings which have already been highlighted as f-l-string-face and
262 ;; thus prevent this highlighting from being applied (actually now that
263 ;; I use `keep' this should work better). But really the part of the
264 ;; selector between [...] should simply not be highlighted.
265 (,(concat
266 "^[ \t]*\\("
267 (if (not sassy)
268 ;; We don't allow / as first char, so as not to
269 ;; take a comment as the beginning of a selector.
270 "[^@/:{}() \t\n][^:{}()]+"
271 ;; Same as for non-sassy except we do want to allow { and }
272 ;; chars in selectors in the case of #{$foo}
273 ;; variable interpolation!
274 (concat "\\(?:" scss--hash-re
275 "\\|[^@/:{}() \t\n#]\\)"
276 "[^:{}()#]*\\(?:" scss--hash-re "[^:{}()#]*\\)*"))
277 ;; Even though pseudo-elements should be prefixed by ::, a
278 ;; single colon is accepted for backward compatibility.
279 "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
280 css-pseudo-element-ids) t)
281 "\\|\\::" (regexp-opt css-pseudo-element-ids t) "\\)"
282 "\\(?:([^)]+)\\)?"
283 (if (not sassy)
284 "[^:{}()\n]*"
285 (concat "[^:{}()\n#]*\\(?:" scss--hash-re "[^:{}()\n#]*\\)*"))
286 "\\)*"
287 "\\)\\(?:\n[ \t]*\\)*{")
288 (1 'css-selector keep))
289 ;; In the above rule, we allow the open-brace to be on some subsequent
290 ;; line. This will only work if we properly mark the intervening text
291 ;; as being part of a multiline element (and even then, this only
292 ;; ensures proper refontification, but not proper discovery).
293 ("^[ \t]*{" (0 (save-excursion
294 (goto-char (match-beginning 0))
295 (skip-chars-backward " \n\t")
296 (put-text-property (point) (match-end 0)
297 'font-lock-multiline t)
298 ;; No face.
299 nil)))
300 ;; Properties. Again, we don't limit ourselves to css-property-ids.
301 (,(concat "\\(?:[{;]\\|^\\)[ \t]*\\("
302 "\\(?:\\(" css-proprietary-nmstart-re "\\)\\|"
303 css-nmstart-re "\\)" css-nmchar-re "*"
304 "\\)\\s-*:")
305 (1 (if (match-end 2) 'css-proprietary-property 'css-property)))
306 ;; Make sure the parens in a url(...) expression receive the
307 ;; default face. This is done because the parens may sometimes
308 ;; receive generic string delimiter syntax (see
309 ;; `css-syntax-propertize-function').
310 (,css--uri-re
311 (1 'default t) (2 'default t))))
312
313 (defvar css-font-lock-keywords (css--font-lock-keywords))
314
315 (defvar css-font-lock-defaults
316 '(css-font-lock-keywords nil t))
317
318 (defcustom css-indent-offset 4
319 "Basic size of one indentation step."
320 :version "22.2"
321 :type 'integer
322 :safe 'integerp)
323
324 (require 'smie)
325
326 (defconst css-smie-grammar
327 (smie-prec2->grammar
328 (smie-precs->prec2 '((assoc ";") (assoc ",") (left ":")))))
329
330 (defun css-smie--forward-token ()
331 (cond
332 ((and (eq (char-before) ?\})
333 (scss-smie--not-interpolation-p)
334 ;; FIXME: If the next char is not whitespace, what should we do?
335 (or (memq (char-after) '(?\s ?\t ?\n))
336 (looking-at comment-start-skip)))
337 (if (memq (char-after) '(?\s ?\t ?\n))
338 (forward-char 1) (forward-comment 1))
339 ";")
340 ((progn (forward-comment (point-max))
341 (looking-at "[;,:]"))
342 (forward-char 1) (match-string 0))
343 (t (smie-default-forward-token))))
344
345 (defun css-smie--backward-token ()
346 (let ((pos (point)))
347 (forward-comment (- (point)))
348 (cond
349 ;; FIXME: If the next char is not whitespace, what should we do?
350 ((and (eq (char-before) ?\}) (scss-smie--not-interpolation-p)
351 (> pos (point))) ";")
352 ((memq (char-before) '(?\; ?\, ?\:))
353 (forward-char -1) (string (char-after)))
354 (t (smie-default-backward-token)))))
355
356 (defun css-smie-rules (kind token)
357 (pcase (cons kind token)
358 (`(:elem . basic) css-indent-offset)
359 (`(:elem . arg) 0)
360 (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467).
361 (`(:before . "{")
362 (when (or (smie-rule-hanging-p) (smie-rule-bolp))
363 (smie-backward-sexp ";")
364 (smie-indent-virtual)))
365 (`(:before . ,(or "{" "("))
366 (if (smie-rule-hanging-p) (smie-rule-parent 0)))))
367
368 ;;; Completion
369
370 (defun css--complete-property ()
371 "Complete property at point."
372 (save-excursion
373 (let ((pos (point)))
374 (skip-chars-backward "-[:alnum:]")
375 (let ((start (point)))
376 (skip-chars-backward " \t\r\n")
377 (when (memq (char-before) '(?\{ ?\;))
378 (list start pos css-property-ids))))))
379
380 (defun css--complete-pseudo-element-or-class ()
381 "Complete pseudo-element or pseudo-class at point."
382 (save-excursion
383 (let ((pos (point)))
384 (skip-chars-backward "-[:alnum:]")
385 (when (eq (char-before) ?\:)
386 (list (point) pos
387 (if (eq (char-before (- (point) 1)) ?\:)
388 css-pseudo-element-ids
389 css-pseudo-class-ids))))))
390
391 (defun css--complete-at-rule ()
392 "Complete at-rule (statement beginning with `@') at point."
393 (save-excursion
394 (let ((pos (point)))
395 (skip-chars-backward "-[:alnum:]")
396 (when (eq (char-before) ?\@)
397 (list (point) pos css-at-ids)))))
398
399 (defun css-completion-at-point ()
400 "Complete current symbol at point.
401 Currently supports completion of CSS properties, pseudo-elements,
402 pseudo-classes, and at-rules."
403 (or (css--complete-property)
404 (css--complete-pseudo-element-or-class)
405 (css--complete-at-rule)))
406
407 ;;;###autoload
408 (define-derived-mode css-mode prog-mode "CSS"
409 "Major mode to edit Cascading Style Sheets."
410 (setq-local font-lock-defaults css-font-lock-defaults)
411 (setq-local comment-start "/*")
412 (setq-local comment-start-skip "/\\*+[ \t]*")
413 (setq-local comment-end "*/")
414 (setq-local comment-end-skip "[ \t]*\\*+/")
415 (setq-local syntax-propertize-function
416 css-syntax-propertize-function)
417 (setq-local fill-paragraph-function #'css-fill-paragraph)
418 (setq-local adaptive-fill-function #'css-adaptive-fill)
419 (setq-local add-log-current-defun-function #'css-current-defun-name)
420 (smie-setup css-smie-grammar #'css-smie-rules
421 :forward-token #'css-smie--forward-token
422 :backward-token #'css-smie--backward-token)
423 (setq-local electric-indent-chars
424 (append css-electric-keys electric-indent-chars))
425 (add-hook 'completion-at-point-functions
426 #'css-completion-at-point nil 'local))
427
428 (defvar comment-continue)
429
430 (defun css-fill-paragraph (&optional justify)
431 (save-excursion
432 ;; Fill succeeding comment when invoked right before a multi-line
433 ;; comment.
434 (when (save-excursion
435 (beginning-of-line)
436 (comment-search-forward (point-at-eol) t))
437 (goto-char (match-end 0)))
438 (let ((ppss (syntax-ppss))
439 (eol (line-end-position)))
440 (cond
441 ((and (nth 4 ppss)
442 (save-excursion
443 (goto-char (nth 8 ppss))
444 (forward-comment 1)
445 (prog1 (not (bolp))
446 (setq eol (point)))))
447 ;; Filling inside a comment whose comment-end marker is not \n.
448 ;; This code is meant to be generic, so that it works not only for
449 ;; css-mode but for all modes.
450 (save-restriction
451 (narrow-to-region (nth 8 ppss) eol)
452 (comment-normalize-vars) ;Will define comment-continue.
453 (let ((fill-paragraph-function nil)
454 (paragraph-separate
455 (if (and comment-continue
456 (string-match "[^ \t]" comment-continue))
457 (concat "\\(?:[ \t]*\\(?:"
458 (regexp-quote comment-continue) "\\|"
459 comment-start-skip "\\|"
460 comment-end-skip "\\)\\)?"
461 "\\(?:" paragraph-separate "\\)")
462 paragraph-separate))
463 (paragraph-start
464 (if (and comment-continue
465 (string-match "[^ \t]" comment-continue))
466 (concat "\\(?:[ \t]*" (regexp-quote comment-continue)
467 "\\)?\\(?:" paragraph-start "\\)")
468 paragraph-start)))
469 (fill-paragraph justify)
470 ;; Don't try filling again.
471 t)))
472
473 ((and (null (nth 8 ppss))
474 (or (nth 1 ppss)
475 (and (ignore-errors
476 (down-list 1)
477 (when (<= (point) eol)
478 (setq ppss (syntax-ppss)))))))
479 (goto-char (nth 1 ppss))
480 (let ((end (save-excursion
481 (ignore-errors (forward-sexp 1) (copy-marker (point) t)))))
482 (when end
483 (while (re-search-forward "[{;}]" end t)
484 (cond
485 ;; This is a false positive inside a string or comment.
486 ((nth 8 (syntax-ppss)) nil)
487 ;; This is a false positive when encountering an
488 ;; interpolated variable (bug#19751).
489 ((eq (char-before (- (point) 1)) ?#) nil)
490 ((eq (char-before) ?\})
491 (save-excursion
492 (forward-char -1)
493 (skip-chars-backward " \t")
494 (when (and (not (bolp))
495 (scss-smie--not-interpolation-p))
496 (newline))))
497 (t
498 (while
499 (progn
500 (setq eol (line-end-position))
501 (and (forward-comment 1)
502 (> (point) eol)
503 ;; A multi-line comment should be on its own line.
504 (save-excursion (forward-comment -1)
505 (when (< (point) eol)
506 (newline)
507 t)))))
508 (if (< (point) eol) (newline)))))
509 (goto-char (nth 1 ppss))
510 (indent-region (line-beginning-position 2) end)
511 ;; Don't use the default filling code.
512 t)))))))
513
514 (defun css-adaptive-fill ()
515 (when (looking-at "[ \t]*/\\*[ \t]*")
516 (let ((str (match-string 0)))
517 (and (string-match "/\\*" str)
518 (replace-match " *" t t str)))))
519
520 (defun css-current-defun-name ()
521 "Return the name of the CSS section at point, or nil."
522 (save-excursion
523 (let ((max (max (point-min) (- (point) 1600)))) ; approx 20 lines back
524 (when (search-backward "{" max t)
525 (skip-chars-backward " \t\r\n")
526 (beginning-of-line)
527 (if (looking-at "^[ \t]*\\([^{\r\n]*[^ {\t\r\n]\\)")
528 (match-string-no-properties 1))))))
529
530 ;;; SCSS mode
531
532 (defvar scss-mode-syntax-table
533 (let ((st (make-syntax-table css-mode-syntax-table)))
534 (modify-syntax-entry ?/ ". 124" st)
535 (modify-syntax-entry ?\n ">" st)
536 st))
537
538 (defvar scss-font-lock-keywords
539 (append `((,(concat "$" css-ident-re) (0 font-lock-variable-name-face)))
540 (css--font-lock-keywords 'sassy)
541 `((,(concat "@mixin[ \t]+\\(" css-ident-re "\\)[ \t]*(")
542 (1 font-lock-function-name-face)))))
543
544 (defun scss-smie--not-interpolation-p ()
545 (save-excursion
546 (forward-char -1)
547 (or (zerop (skip-chars-backward "-[:alnum:]"))
548 (not (looking-back "#{\\$" (- (point) 3))))))
549
550 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.scss\\'" . scss-mode))
551 ;;;###autoload
552 (define-derived-mode scss-mode css-mode "SCSS"
553 "Major mode to edit \"Sassy CSS\" files."
554 (setq-local comment-start "// ")
555 (setq-local comment-end "")
556 (setq-local comment-continue " *")
557 (setq-local comment-start-skip "/[*/]+[ \t]*")
558 (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
559 (setq-local font-lock-defaults '(scss-font-lock-keywords nil t)))
560
561 (provide 'css-mode)
562 ;;; css-mode.el ends here