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