1 ;;; flymake-css.el --- Flymake setup for css files
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2009-11-21 Sat
11 ;; Features that might be required by this library:
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; See variable `flymake-css-validator-jar' for instructions for how
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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.
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.
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.
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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"))))
62 (defvar flymake-css-err-line-pattern-re '(("^file:\\([^:]+\\):\\([^:]+\\):\\(.*\\)" 1 2 nil 3))
63 "Regexp matching CSS error messages")
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
71 http://www.emacswiki.org/emacs/FlymakeCSS
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:
77 * commons-collections-3.2.1.jar
81 * commons-lang-2.4.jar
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'
94 Test validating some CSS file by running:
96 java -jar css-validator.jar file:somecssfile.css"
99 ;;(setq flymake-css-validator-jar "c:/dl/programs/css-valid/css-validator.jar")
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
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))
111 (list "-jar" flymake-css-validator-jar
113 (concat "file:" local-file)))))
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)))
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
128 (ad-set-arg 2 (xml-substitute-numeric-entities (ad-get-arg 2))))
130 ;; Fix-me: remove when this has been giving its proper place in Emacs.
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
139 This function replaces numeric entities in the input STRING and
140 returns the modified string. For example \"*\" gets replaced
142 (if (and string (stringp string))
144 (while (string-match "&#\\([0-9]+\\);" string start)
146 (setq string (replace-match
147 (string (read (substring string
152 (setq start (1+ (match-beginning 0))))
157 ;;(eval-after-load 'css-mode (flymake-css-load))
159 (provide 'flymake-css)
160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 ;;; flymake-css.el ends here