]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/css-mode.el
Merge from emacs-24; up to 2012-12-17T11:17:34Z!rgm@gnu.org
[gnu-emacs] / lisp / textmodes / css-mode.el
index b611261723a5b9b6db33d8d347164f96701949fe..cb19c018839e5a19c6e2960d1a5fe366508891d5 100644 (file)
@@ -1,6 +1,6 @@
-;;; css-mode.el --- Major mode to edit CSS files
+;;; css-mode.el --- Major mode to edit CSS files -*- lexical-binding: t -*-
 
-;; Copyright (C) 2006-201 Free Software Foundation, Inc.
+;; Copyright (C) 2006-2013 Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: hypermedia
@@ -37,7 +37,6 @@
   "Cascading Style Sheets (CSS) editing mode."
   :group 'languages)
 
-(eval-when-compile (require 'cl))
 
 (defun css-extract-keyword-list (res)
   (with-temp-buffer
 (defconst css-nmstart-re (concat "\\(?:[[:alpha:]]\\|" css-escapes-re "\\)"))
 (defconst css-ident-re (concat css-nmstart-re css-nmchar-re "*"))
 (defconst css-proprietary-nmstart-re ;; Vendor-specific properties.
-  "[-_]\\(?:ms\\|moz\\|o\\|webkit\\|khtml\\)-")
+  (concat "[-_]" (regexp-opt '("ms" "moz" "o" "khtml" "webkit")) "-"))
 (defconst css-name-re (concat css-nmchar-re "+"))
 
 (defface css-selector '((t :inherit font-lock-function-name-face))
     ;; thus prevent this highlighting from being applied (actually now that
     ;; I use `append' this should work better).  But really the part of hte
     ;; selector between [...] should simply not be highlighted.
-    (,(concat "^\\([ \t]*[^@:{\n][^:{\n]+\\(?::" (regexp-opt css-pseudo-ids t)
+    (,(concat "^\\([ \t]*[^@:{}\n][^:{}]+\\(?::" (regexp-opt css-pseudo-ids t)
               "\\(?:([^)]+)\\)?[^:{\n]*\\)*\\)\\(?:\n[ \t]*\\)*{")
      (1 'css-selector append))
     ;; In the above rule, we allow the open-brace to be on some subsequent
 ;;;###autoload
 (define-derived-mode css-mode fundamental-mode "CSS"
   "Major mode to edit Cascading Style Sheets."
-  (set (make-local-variable 'font-lock-defaults) css-font-lock-defaults)
-  (set (make-local-variable 'comment-start) "/*")
-  (set (make-local-variable 'comment-start-skip) "/\\*+[ \t]*")
-  (set (make-local-variable 'comment-end) "*/")
-  (set (make-local-variable 'comment-end-skip) "[ \t]*\\*+/")
-  (set (make-local-variable 'forward-sexp-function) 'css-forward-sexp)
-  (set (make-local-variable 'parse-sexp-ignore-comments) t)
-  (set (make-local-variable 'indent-line-function) 'css-indent-line)
-  (set (make-local-variable 'fill-paragraph-function)
-       'css-fill-paragraph)
+  (setq-local font-lock-defaults css-font-lock-defaults)
+  (setq-local comment-start "/*")
+  (setq-local comment-start-skip "/\\*+[ \t]*")
+  (setq-local comment-end "*/")
+  (setq-local comment-end-skip "[ \t]*\\*+/")
+  (setq-local forward-sexp-function 'css-forward-sexp)
+  (setq-local parse-sexp-ignore-comments t)
+  (setq-local indent-line-function 'css-indent-line)
+  (setq-local fill-paragraph-function 'css-fill-paragraph)
+  (setq-local add-log-current-defun-function #'css-current-defun-name)
   (when css-electric-keys
     (let ((fc (make-char-table 'auto-fill-chars)))
       (set-char-table-parent fc auto-fill-chars)
       (dolist (c css-electric-keys)
         (aset fc c 'indent-according-to-mode))
-      (set (make-local-variable 'auto-fill-chars) fc))))
+      (setq-local auto-fill-chars fc))))
 
 (defvar comment-continue)
 
           (save-excursion (indent-line-to indent))
         (indent-line-to indent)))))
 
+(defun css-current-defun-name ()
+  "Return the name of the CSS section at point, or nil."
+  (save-excursion
+    (let ((max (max (point-min) (- (point) 1600))))  ; approx 20 lines back
+      (when (search-backward "{" max t)
+       (skip-chars-backward " \t\r\n")
+       (beginning-of-line)
+       (if (looking-at "^[ \t]*\\([^{\r\n]*[^ {\t\r\n]\\)")
+           (match-string-no-properties 1))))))
+
 (provide 'css-mode)
 ;;; css-mode.el ends here