annotate lisp/textmodes/css-mode.el @ 105416:cb0fd5493ae6

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