]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/related/flymake-css.el
remove toolbar and menubar
[.emacs.d.git] / emacs / nxhtml / related / flymake-css.el
1 ;;; flymake-css.el --- Flymake setup for css files
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2009-11-21 Sat
5 ;; Version:
6 ;; Last-Updated:
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;;  See variable `flymake-css-validator-jar' for instructions for how
20 ;;  to set this up.
21 ;;
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;;
24 ;;; Change log:
25 ;;
26 ;;
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;
29 ;; This program is free software; you can redistribute it and/or
30 ;; modify it under the terms of the GNU General Public License as
31 ;; published by the Free Software Foundation; either version 3, or
32 ;; (at your option) any later version.
33 ;;
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
37 ;; General Public License for more details.
38 ;;
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING.  If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
43 ;;
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 ;;
46 ;;; Code:
47
48
49 (require 'flymake)
50 (require 'xml)
51
52
53 (defcustom flymake-allowed-css-file-name-masks '(("\\.css\\'" flymake-css-init))
54   "Filename extensions that switch on js syntax checks."
55   :type '(repeat (list (regexp :tag "File name regexp")
56                        (function :tag "Init function")
57                        (choice (const :tag "No cleanup function" nil)
58                                (function :tag "Cleanup function"))))
59   :group 'flymake)
60
61
62 (defvar flymake-css-err-line-pattern-re '(("^file:\\([^:]+\\):\\([^:]+\\):\\(.*\\)" 1 2 nil 3))
63   "Regexp matching CSS error messages")
64
65 (defcustom flymake-css-validator-jar "~/bin/css-validator.jar"
66   "Full path to css-validor.jar file.
67 You need the css-validator.jar and some other files for flymake
68 for CSS to work. The instructions below tell you how to get and
69 install it. The instructions are copied from
70
71   http://www.emacswiki.org/emacs/FlymakeCSS
72
73 Get http://www.w3.org/QA/Tools/css-validator/css-validator.jar
74 create a directory named ‘lib’ in the same directory. Copy to the
75 ‘lib’ dir the following jars:
76
77  * commons-collections-3.2.1.jar
78  * jigsaw.jar
79  * velocity-1.6.1.jar
80  * xml-apis.jar
81  * commons-lang-2.4.jar
82  * tagsoup-1.2.jar
83  * xercesImpl.jar
84
85 From:
86
87  URL `http://jigsaw.w3.org/Distrib/jigsaw_2.2.6.tar.gz'
88  URL `http://www.apache.org/dist/commons/collections/binaries/commons-collections-3.2.1-bin.tar.gz'
89  URL `http://www.apache.org/dist/commons/lang/binaries/commons-lang-2.4-bin.tar.gz'
90  URL `http://www.apache.org/dist/velocity/engine/1.6.1/velocity-1.6.1.tar.gz'
91  URL `http://www.apache.org/dist/xerces/j/Xerces-J-bin.2.9.1.tar.gz'
92  URL `http://home.ccil.org/~cowan/XML/tagsoup/tagsoup-1.2.jar'
93
94 Test validating some CSS file by running:
95
96   java -jar css-validator.jar file:somecssfile.css"
97   :type 'file
98   :group 'flymake)
99 ;;(setq flymake-css-validator-jar "c:/dl/programs/css-valid/css-validator.jar")
100
101 (defun flymake-css-init ()
102   (let* ((temp-file (flymake-init-create-temp-buffer-copy
103                      'flymake-create-temp-inplace))
104          (local-file (file-relative-name
105                       temp-file
106                       (file-name-directory buffer-file-name))))
107     (unless (file-exists-p flymake-css-validator-jar)
108       (error "Can't find css-validator.jar: %s\n\nPlease customize option flymake-css-validator-jar\n"
109              flymake-css-validator-jar))
110     (list "java"
111           (list "-jar" flymake-css-validator-jar
112                 "-output" "gnu"
113                 (concat "file:" local-file)))))
114
115 ;;;###autoload
116 (defun flymake-css-load ()
117   (dolist (rec flymake-allowed-css-file-name-masks)
118     (add-to-list 'flymake-allowed-file-name-masks rec))
119   (dolist (rec flymake-css-err-line-pattern-re)
120     (add-to-list 'flymake-err-line-patterns rec)))
121
122
123 ;;(defun flymake-make-overlay (beg end tooltip-text face mouse-face)
124 (defadvice flymake-make-overlay (before
125                                  flymake-css-ad-flymake-make-overlay
126                                  activate
127                                  compile)
128   (ad-set-arg 2 (xml-substitute-numeric-entities (ad-get-arg 2))))
129
130 ;; Fix-me: remove when this has been giving its proper place in Emacs.
131 (eval-when-compile
132   (unless (fboundp 'xml-substitute-numeric-entities)
133     (message "Use Emacs 22 workaround for newsticker--decode-numeric-entities")
134     (defun xml-substitute-numeric-entities (string)
135     "Decode SGML numeric entities by their respective utf characters.
136 This is just a copy of the function in newst-backen.el for Emacs
137 22 users.
138
139 This function replaces numeric entities in the input STRING and
140 returns the modified string.  For example \"*\" gets replaced
141 by \"*\"."
142     (if (and string (stringp string))
143         (let ((start 0))
144           (while (string-match "&#\\([0-9]+\\);" string start)
145             (condition-case nil
146                 (setq string (replace-match
147                               (string (read (substring string
148                                                        (match-beginning 1)
149                                                        (match-end 1))))
150                               nil nil string))
151               (error nil))
152             (setq start (1+ (match-beginning 0))))
153           string)
154       nil))
155     ))
156
157 ;;(eval-after-load 'css-mode (flymake-css-load))
158
159 (provide 'flymake-css)
160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 ;;; flymake-css.el ends here