annotate lisp/textmodes/css-mode.el @ 80601:08400e604a09

*** empty log message ***
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Mon, 07 Jul 2008 09:31:49 +0000
parents 4af0bb174714
children d999f30304bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; css-mode.el --- Major mode to edit CSS files
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
79719
dc100f64b2b7 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 79187
diff changeset
3 ;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6 ;; Keywords: hypermedia
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8 ;; This file is free software; you can redistribute it and/or modify
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
78225
b6d25790aab2 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 77923
diff changeset
10 ;; the Free Software Foundation; either version 3, or (at your option)
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11 ;; any later version.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13 ;; This file is distributed in the hope that it will be useful,
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16 ;; GNU General Public License for more details.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21 ;; Boston, MA 02110-1301, USA.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;;; Commentary:
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;; Yet another CSS mode.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;;; Todo:
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;; - electric ; and }
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;; - filling code with auto-fill-mode
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;; - completion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;; - fix font-lock errors with multi-line selectors
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;;; Code:
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35
79187
e3d75658c018 Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78825
diff changeset
36 (eval-when-compile (require 'cl))
e3d75658c018 Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78825
diff changeset
37
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 (defun css-extract-keyword-list (res)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 (with-temp-buffer
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 (url-insert-file-contents "http://www.w3.org/TR/REC-CSS2/css2.txt")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 (goto-char (point-max))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 (search-backward "Appendix H. Index")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 (forward-line)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 (delete-region (point-min) (point))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 (let ((result nil)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 keys)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 (dolist (re res)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 (goto-char (point-min))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 (setq keys nil)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 (while (re-search-forward (cdr re) nil t)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 (push (match-string 1) keys))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 (push (cons (car re) (sort keys 'string-lessp)) result))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 (nreverse result))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 (defun css-extract-parse-val-grammar (string env)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 (let ((start 0)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 (elems ())
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 name)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 (while (string-match
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 (concat "\\(?:"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 (concat "<a [^>]+><span [^>]+>\\(?:"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 "&lt;\\([^&]+\\)&gt;\\|'\\([^']+\\)'"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63 "\\)</span></a>")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 "\\|" "\\(\\[\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 "\\|" "\\(]\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 "\\|" "\\(||\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 "\\|" "\\(|\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 "\\|" "\\([*+?]\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69 "\\|" "\\({[^}]+}\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 "\\|" "\\(\\w+\\(?:-\\w+\\)*\\)"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 "\\)[ \t\n]*")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 string start)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 ;; (assert (eq start (match-beginning 0)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 (setq start (match-end 0))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 (cond
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 ;; Reference to a type of value.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 ((setq name (match-string-no-properties 1 string))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 (push (intern name) elems))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 ;; Reference to another property's values.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 ((setq name (match-string-no-properties 2 string))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 (setq elems (delete-dups (append (cdr (assoc name env)) elems))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 ;; A literal
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 ((setq name (match-string-no-properties 9 string))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 (push name elems))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 ;; We just ignore the rest. I.e. we ignore the structure because
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 ;; it's too difficult to exploit anyway (it would allow us to only
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 ;; complete top/center/bottom after one of left/center/right and
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 ;; vice-versa).
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 (t nil)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 elems))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 (defun css-extract-props-and-vals ()
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 (with-temp-buffer
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 (url-insert-file-contents "http://www.w3.org/TR/CSS21/propidx.html")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 (goto-char (point-min))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 (let ((props ()))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 (while (re-search-forward "#propdef-\\([^\"]+\\)\"><span class=\"propinst-\\1 xref\">'\\1'</span></a>" nil t)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 (let ((prop (match-string-no-properties 1)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 (goto-char (match-end 0))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 (search-forward "<td>")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 (let ((vals-string (buffer-substring (point)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 (progn
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 (re-search-forward "[ \t\n]+|[ \t\n]+<a href=\"cascade.html#value-def-inherit\" class=\"noxref\"><span class=\"value-inst-inherit\">inherit</span></a>")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 (match-beginning 0)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 ;;
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 (push (cons prop (css-extract-parse-val-grammar vals-string props))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 props)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 props)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 ;; Extraction was done with:
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 ;; (css-extract-keyword-list
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 ;; '((pseudo . "^ +\\* :\\([^ \n,]+\\)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 ;; (at . "^ +\\* @\\([^ \n,]+\\)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 ;; (descriptor . "^ +\\* '\\([^ '\n]+\\)' (descriptor)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 ;; (media . "^ +\\* '\\([^ '\n]+\\)' media group")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 ;; (property . "^ +\\* '\\([^ '\n]+\\)',")))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 (defconst css-pseudo-ids
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 '("active" "after" "before" "first" "first-child" "first-letter" "first-line"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 "focus" "hover" "lang" "left" "link" "right" "visited")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 "Identifiers for pseudo-elements and pseudo-classes.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 (defconst css-at-ids
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 '("charset" "font-face" "import" "media" "page")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 "Identifiers that appear in the form @foo.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 (defconst css-descriptor-ids
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 '("ascent" "baseline" "bbox" "cap-height" "centerline" "definition-src"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 "descent" "font-family" "font-size" "font-stretch" "font-style"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132 "font-variant" "font-weight" "mathline" "panose-1" "slope" "src" "stemh"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 "stemv" "topline" "unicode-range" "units-per-em" "widths" "x-height")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 "Identifiers for font descriptors.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 (defconst css-media-ids
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137 '("all" "aural" "bitmap" "continuous" "grid" "paged" "static" "tactile"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 "visual")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139 "Identifiers for types of media.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 (defconst css-property-ids
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 '("azimuth" "background" "background-attachment" "background-color"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 "background-image" "background-position" "background-repeat" "block"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 "border" "border-bottom" "border-bottom-color" "border-bottom-style"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 "border-bottom-width" "border-collapse" "border-color" "border-left"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 "border-left-color" "border-left-style" "border-left-width" "border-right"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 "border-right-color" "border-right-style" "border-right-width"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 "border-spacing" "border-style" "border-top" "border-top-color"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149 "border-top-style" "border-top-width" "border-width" "bottom"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 "caption-side" "clear" "clip" "color" "compact" "content"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 "counter-increment" "counter-reset" "cue" "cue-after" "cue-before"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152 "cursor" "dashed" "direction" "display" "dotted" "double" "elevation"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 "empty-cells" "float" "font" "font-family" "font-size" "font-size-adjust"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 "font-stretch" "font-style" "font-variant" "font-weight" "groove" "height"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 "hidden" "inline" "inline-table" "inset" "left" "letter-spacing"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 "line-height" "list-item" "list-style" "list-style-image"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 "list-style-position" "list-style-type" "margin" "margin-bottom"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 "margin-left" "margin-right" "margin-top" "marker-offset" "marks"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 "max-height" "max-width" "min-height" "min-width" "orphans" "outline"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160 "outline-color" "outline-style" "outline-width" "outset" "overflow"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 "padding" "padding-bottom" "padding-left" "padding-right" "padding-top"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 "page" "page-break-after" "page-break-before" "page-break-inside" "pause"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 "pause-after" "pause-before" "pitch" "pitch-range" "play-during" "position"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 "quotes" "richness" "ridge" "right" "run-in" "size" "solid" "speak"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 "speak-header" "speak-numeral" "speak-punctuation" "speech-rate" "stress"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 "table" "table-caption" "table-cell" "table-column" "table-column-group"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 "table-footer-group" "table-header-group" "table-layout" "table-row"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 "table-row-group" "text-align" "text-decoration" "text-indent"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 "text-shadow" "text-transform" "top" "unicode-bidi" "vertical-align"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 "visibility" "voice-family" "volume" "white-space" "widows" "width"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 "word-spacing" "z-index")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 "Identifiers for properties.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173
78825
6ba709e4adda (css-electric-keys): electrick->electric.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78225
diff changeset
174 (defcustom css-electric-keys '(?\} ?\;) ;; '()
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 "Self inserting keys which should trigger re-indentation."
80261
4af0bb174714 * textmodes/css-mode.el (css-indent-offset, css-electric-keys):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 79719
diff changeset
176 :version "22.2"
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 :type '(repeat character)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 :options '((?\} ?\;)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 (defvar css-mode-syntax-table
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181 (let ((st (make-syntax-table)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 ;; C-style comments.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 (modify-syntax-entry ?/ ". 14" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 (modify-syntax-entry ?* ". 23" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 ;; Strings.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 (modify-syntax-entry ?\" "\"" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 (modify-syntax-entry ?\' "\"" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 ;; Blocks.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 (modify-syntax-entry ?\{ "(}" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 (modify-syntax-entry ?\} "){" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 ;; Args in url(...) thingies and other "function calls".
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 (modify-syntax-entry ?\( "()" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 (modify-syntax-entry ?\) ")(" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 ;; To match attributes in selectors.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 (modify-syntax-entry ?\[ "(]" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 (modify-syntax-entry ?\] ")[" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 ;; Special chars that sometimes come at the beginning of words.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 (modify-syntax-entry ?@ "'" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 ;; (modify-syntax-entry ?: "'" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 (modify-syntax-entry ?# "'" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 ;; Distinction between words and symbols.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 (modify-syntax-entry ?- "_" st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 st))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 (defconst css-escapes-re
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 "\\\\\\(?:[^\000-\037\177]\\|[0-9a-fA-F]+[ \n\t\r\f]?\\)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 (defconst css-nmchar-re (concat "\\(?:[-[:alnum:]]\\|" css-escapes-re "\\)"))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 (defconst css-nmstart-re (concat "\\(?:[[:alpha:]]\\|" css-escapes-re "\\)"))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 (defconst css-ident-re (concat css-nmstart-re css-nmchar-re "*"))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (defconst css-name-re (concat css-nmchar-re "+"))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 (defface css-selector '((t :inherit font-lock-function-name-face))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 "Face to use for selectors.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 (defface css-property '((t :inherit font-lock-variable-name-face))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 "Face to use for properties.")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217 (defvar css-font-lock-keywords
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 `(("!\\s-*important" . font-lock-builtin-face)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 ;; Atrules keywords. IDs not in css-at-ids are valid (ignored).
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 ;; In fact the regexp should probably be
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 ;; (,(concat "\\(@" css-ident-re "\\)\\([ \t\n][^;{]*\\)[;{]")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 ;; (1 font-lock-builtin-face))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 ;; Since "An at-rule consists of everything up to and including the next
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 ;; semicolon (;) or the next block, whichever comes first."
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 (,(concat "@" css-ident-re) . font-lock-builtin-face)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 ;; Selectors.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 ;; FIXME: attribute selectors don't work well because they may contain
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 ;; strings which have already been highlighted as f-l-string-face and
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 ;; thus prevent this highlighting from being applied (actually now that
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 ;; I use `append' this should work better). But really the part of hte
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 ;; selector between [...] should simply not be highlighted.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (,(concat "^\\([ \t]*[^@:{\n][^:{\n]+\\(?::" (regexp-opt css-pseudo-ids t)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 "\\(?:([^)]+)\\)?[^:{\n]*\\)*\\)\\(?:\n[ \t]*\\)*{")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 (1 'css-selector append))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 ;; In the above rule, we allow the open-brace to be on some subsequent
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 ;; line. This will only work if we properly mark the intervening text
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237 ;; as being part of a multiline element (and even then, this only
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 ;; ensures proper refontification, but not proper discovery).
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 ("^[ \t]*{" (0 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 (goto-char (match-beginning 0))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (skip-chars-backward " \n\t")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 (put-text-property (point) (match-end 0)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243 'font-lock-multiline t)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 ;; No face.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 nil)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 ;; Properties. Again, we don't limit ourselves to css-property-ids.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 (,(concat "\\(?:[{;]\\|^\\)[ \t]*\\(" css-ident-re "\\)\\s-*:")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 (1 'css-property))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 (defvar css-font-lock-defaults
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 '(css-font-lock-keywords nil t))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253 (unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 ;;;###autoload
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257 (define-derived-mode css-mode prog-mode "CSS"
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 "Major mode to edit Cascading Style Sheets."
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
259 (set (make-local-variable 'font-lock-defaults) css-font-lock-defaults)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
260 (set (make-local-variable 'comment-start) "/*")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
261 (set (make-local-variable 'comment-start-skip) "/\\*+[ \t]*")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
262 (set (make-local-variable 'comment-end) "*/")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
263 (set (make-local-variable 'comment-end-skip) "[ \t]*\\*+/")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
264 (set (make-local-variable 'forward-sexp-function) 'css-forward-sexp)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
265 (set (make-local-variable 'parse-sexp-ignore-comments) t)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
266 (set (make-local-variable 'indent-line-function) 'css-indent-line)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
267 (set (make-local-variable 'fill-paragraph-function)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
268 'css-fill-paragraph)
78825
6ba709e4adda (css-electric-keys): electrick->electric.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78225
diff changeset
269 (when css-electric-keys
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
270 (let ((fc (make-char-table 'auto-fill-chars)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
271 (set-char-table-parent fc auto-fill-chars)
78825
6ba709e4adda (css-electric-keys): electrick->electric.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78225
diff changeset
272 (dolist (c css-electric-keys)
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
273 (aset fc c 'indent-according-to-mode))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
274 (set (make-local-variable 'auto-fill-chars) fc))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
275
79187
e3d75658c018 Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78825
diff changeset
276 (defvar comment-continue)
e3d75658c018 Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78825
diff changeset
277
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
278 (defun css-fill-paragraph (&optional justify)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
279 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
280 (let ((ppss (syntax-ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
281 (eol (line-end-position)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
282 (cond
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
283 ((and (nth 4 ppss)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
284 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
285 (goto-char (nth 8 ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
286 (forward-comment 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
287 (prog1 (not (bolp))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
288 (setq eol (point)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
289 ;; Filling inside a comment whose comment-end marker is not \n.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
290 ;; This code is meant to be generic, so that it works not only for
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
291 ;; css-mode but for all modes.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
292 (save-restriction
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
293 (narrow-to-region (nth 8 ppss) eol)
79187
e3d75658c018 Require CL.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78825
diff changeset
294 (comment-normalize-vars) ;Will define comment-continue.
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
295 (let ((fill-paragraph-function nil)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
296 (paragraph-separate
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
297 (if (and comment-continue
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
298 (string-match "[^ \t]" comment-continue))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
299 (concat "\\(?:[ \t]*" (regexp-quote comment-continue)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
300 "\\)?\\(?:" paragraph-separate "\\)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
301 paragraph-separate))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
302 (paragraph-start
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
303 (if (and comment-continue
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
304 (string-match "[^ \t]" comment-continue))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
305 (concat "\\(?:[ \t]*" (regexp-quote comment-continue)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
306 "\\)?\\(?:" paragraph-start "\\)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
307 paragraph-start)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
308 (fill-paragraph justify)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
309 ;; Don't try filling again.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
310 t)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
311
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
312 ((and (null (nth 8 ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
313 (or (nth 1 ppss)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
314 (and (ignore-errors
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
315 (down-list 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
316 (when (<= (point) eol)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
317 (setq ppss (syntax-ppss)))))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
318 (goto-char (nth 1 ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
319 (let ((end (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
320 (ignore-errors (forward-sexp 1) (copy-marker (point) t)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
321 (when end
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
322 (while (re-search-forward "[{;}]" end t)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
323 (cond
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
324 ;; This is a false positive inside a string or comment.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
325 ((nth 8 (syntax-ppss)) nil)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
326 ((eq (char-before) ?\})
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
327 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
328 (forward-char -1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
329 (skip-chars-backward " \t")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
330 (unless (bolp) (newline))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
331 (t
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
332 (while
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
333 (progn
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
334 (setq eol (line-end-position))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
335 (and (forward-comment 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
336 (> (point) eol)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
337 ;; A multi-line comment should be on its own line.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
338 (save-excursion (forward-comment -1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
339 (when (< (point) eol)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
340 (newline)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
341 t)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
342 (if (< (point) eol) (newline)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
343 (goto-char (nth 1 ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
344 (indent-region (line-beginning-position 2) end)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
345 ;; Don't use the default filling code.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
346 t)))))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
347
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
348 ;;; Navigation and indentation.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
349
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
350 (defconst css-navigation-syntax-table
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
351 (let ((st (make-syntax-table css-mode-syntax-table)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
352 (map-char-table (lambda (c v)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
353 ;; Turn punctuation (code = 1) into symbol (code = 1).
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
354 (if (eq (car-safe v) 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
355 (aset st c (cons 3 (cdr v)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
356 st)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
357 st))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
358
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
359 (defun css-backward-sexp (n)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
360 (let ((forward-sexp-function nil))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
361 (if (< n 0) (css-forward-sexp (- n))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
362 (while (> n 0)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
363 (setq n (1- n))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
364 (forward-comment (- (point-max)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
365 (if (not (eq (char-before) ?\;))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
366 (backward-sexp 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
367 (while (progn (backward-sexp 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
368 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
369 (forward-comment (- (point-max)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
370 ;; FIXME: We should also skip punctuation.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
371 (not (memq (char-before) '(?\; ?\{)))))))))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
372
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
373 (defun css-forward-sexp (n)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
374 (let ((forward-sexp-function nil))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
375 (if (< n 0) (css-backward-sexp (- n))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
376 (while (> n 0)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
377 (setq n (1- n))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
378 (forward-comment (point-max))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
379 (if (not (eq (char-after) ?\;))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
380 (forward-sexp 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
381 (while (progn (forward-sexp 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
382 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
383 (forward-comment (point-max))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
384 ;; FIXME: We should also skip punctuation.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
385 (not (memq (char-after) '(?\; ?\})))))))))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
386
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
387 (defun css-indent-calculate-virtual ()
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
388 (if (or (save-excursion (skip-chars-backward " \t") (bolp))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
389 (if (looking-at "\\s(")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
390 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
391 (forward-char 1) (skip-chars-forward " \t")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
392 (not (or (eolp) (looking-at comment-start-skip))))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
393 (current-column)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
394 (css-indent-calculate)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
395
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
396 (defcustom css-indent-offset 4
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
397 "Basic size of one indentation step."
80261
4af0bb174714 * textmodes/css-mode.el (css-indent-offset, css-electric-keys):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 79719
diff changeset
398 :version "22.2"
77923
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
399 :type 'integer)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
400
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
401 (defun css-indent-calculate ()
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
402 (let ((ppss (syntax-ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
403 pos)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
404 (with-syntax-table css-navigation-syntax-table
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
405 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
406 (cond
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
407 ;; Inside a string.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
408 ((nth 3 ppss) 'noindent)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
409 ;; Inside a comment.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
410 ((nth 4 ppss)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
411 (setq pos (point))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
412 (forward-line -1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
413 (skip-chars-forward " \t")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
414 (if (>= (nth 8 ppss) (point))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
415 (progn
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
416 (goto-char (nth 8 ppss))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
417 (if (eq (char-after pos) ?*)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
418 (forward-char 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
419 (if (not (looking-at comment-start-skip))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
420 (error "Internal css-mode error")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
421 (goto-char (match-end 0))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
422 (current-column))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
423 (if (and (eq (char-after pos) ?*) (eq (char-after) ?*))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
424 (current-column)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
425 ;; 'noindent
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
426 (current-column)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
427 )))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
428 ;; In normal code.
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
429 (t
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
430 (or
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
431 (when (looking-at "\\s)")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
432 (forward-char 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
433 (backward-sexp 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
434 (css-indent-calculate-virtual))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
435 (when (looking-at comment-start-skip)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
436 (forward-comment (point-max))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
437 (css-indent-calculate))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
438 (when (save-excursion (forward-comment (- (point-max)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
439 (setq pos (point))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
440 (eq (char-syntax (preceding-char)) ?\())
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
441 (goto-char (1- pos))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
442 (if (not (looking-at "\\s([ \t]*"))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
443 (error "Internal css-mode error")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
444 (if (or (memq (char-after (match-end 0)) '(?\n nil))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
445 (save-excursion (goto-char (match-end 0))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
446 (looking-at comment-start-skip)))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
447 (+ (css-indent-calculate-virtual) css-indent-offset)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
448 (progn (goto-char (match-end 0)) (current-column)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
449 (progn
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
450 (css-backward-sexp 1)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
451 (if (looking-at "\\s(")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
452 (css-indent-calculate)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
453 (css-indent-calculate-virtual))))))))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
454
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
455
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
456 (defun css-indent-line ()
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
457 "Indent current line according to CSS indentation rules."
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
458 (interactive)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
459 (let* ((savep (point))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
460 (forward-sexp-function nil)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
461 (indent (condition-case nil
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
462 (save-excursion
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
463 (forward-line 0)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
464 (skip-chars-forward " \t")
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
465 (if (>= (point) savep) (setq savep nil))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
466 (css-indent-calculate))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
467 (error nil))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
468 (if (not (numberp indent)) 'noindent
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
469 (if savep
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
470 (save-excursion (indent-line-to indent))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
471 (indent-line-to indent)))))
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
472
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
473 (provide 'css-mode)
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
474 ;; arch-tag: b4d8b8e2-b130-4e74-b3aa-cd8f1ab659d0
7cbee079e548 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
475 ;;; css-mode.el ends here