|
| 1 | +;;; flymake-csslint.el --- making flymake work with CSSLint |
| 2 | + |
| 3 | +;; Copyright (C) 2011 Wilfred Hughes <me@wilfred.me.uk> |
| 4 | +;; Copyright (C) 2011 Arne J,Ax(Brgensen <arne@arnested.dk> |
| 5 | + |
| 6 | +;; Author: Arne J,Ax(Brgensen <arne@arnested.dk> |
| 7 | +;; Created: 1 December 2011 |
| 8 | +;; Version: 1.0 |
| 9 | +;; Keywords: flymake, csslint, css |
| 10 | + |
| 11 | +;; This file is not part of GNU Emacs. |
| 12 | +;; However, it is distributed under the same license. |
| 13 | + |
| 14 | +;; GNU Emacs is free software; you can redistribute it and/or modify |
| 15 | +;; it under the terms of the GNU General Public License as published by |
| 16 | +;; the Free Software Foundation; either version 3, or (at your option) |
| 17 | +;; any later version. |
| 18 | + |
| 19 | +;; GNU Emacs is distributed in the hope that it will be useful, |
| 20 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +;; GNU General Public License for more details. |
| 23 | + |
| 24 | +;; You should have received a copy of the GNU General Public License |
| 25 | +;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 26 | +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 27 | +;; Boston, MA 02110-1301, USA. |
| 28 | + |
| 29 | +;;; Commentary |
| 30 | + |
| 31 | +;; To use CSSLint with emacs, you will need CSSLint installed and available on |
| 32 | +;; your path. You should be able to do |
| 33 | + |
| 34 | +;; $ csslint |
| 35 | + |
| 36 | +;; without problem. To do this, you can install node.js, npm and |
| 37 | +;; csslint by doing the following: |
| 38 | + |
| 39 | +;; $ apt-get install nodejs # or your distro / OS equivalent |
| 40 | +;; $ curl http://npmjs.org/install.sh | sh |
| 41 | +;; $ npm install -g csslint |
| 42 | + |
| 43 | +;; flymake-csslint.el is very much based on flymake-jshint.el by |
| 44 | +;; Wilfred Hughes <me@wilfred.me.uk>. |
| 45 | + |
| 46 | +;;; Usage |
| 47 | + |
| 48 | +;; Add to your emacs config: |
| 49 | + |
| 50 | +;; (require 'flymake-csslint) |
| 51 | +;; (add-hook 'css-mode-hook 'flymake-mode) |
| 52 | + |
| 53 | +;; making sure that flymake-csslint.el is on your load-path. If not, |
| 54 | +;; also add to your config: |
| 55 | + |
| 56 | +;; (add-to-list 'load-path "~/.emacs.d/path/to/flymake-csslint.el") |
| 57 | + |
| 58 | +;;; Debugging |
| 59 | + |
| 60 | +;; If CSSLint isn't working for any reason, execute |
| 61 | + |
| 62 | +;; M-x set-variable flymake-log-level <RET> 3 |
| 63 | + |
| 64 | +;; and you will see what is going wrong listed in the *Messages* |
| 65 | +;; buffer. |
| 66 | + |
| 67 | +(require 'flymake) |
| 68 | + |
| 69 | +(defun flymake-csslint-init () |
| 70 | + (let* ((temp-file (flymake-init-create-temp-buffer-copy |
| 71 | + 'flymake-create-temp-inplace)) |
| 72 | + (local-file (file-relative-name |
| 73 | + temp-file |
| 74 | + (file-name-directory buffer-file-name)))) |
| 75 | + (list "csslint" (list "--format=compact" local-file)))) |
| 76 | + |
| 77 | +(setq flymake-allowed-file-name-masks |
| 78 | + (cons '(".+\\.css$" |
| 79 | + flymake-csslint-init |
| 80 | + flymake-simple-cleanup |
| 81 | + flymake-get-real-file-name) |
| 82 | + flymake-allowed-file-name-masks)) |
| 83 | + |
| 84 | +(setq flymake-err-line-patterns |
| 85 | + (cons '("^\\(.*\\): line \\([[:digit:]]+\\), col \\([[:digit:]]+\\), \\(.+\\)$" |
| 86 | + 1 2 3 4) |
| 87 | + flymake-err-line-patterns)) |
| 88 | + |
| 89 | +; load flymake automatically in CSS mode |
| 90 | +(add-hook 'css-mode-hook 'flymake-mode) |
| 91 | + |
| 92 | +(provide 'flymake-csslint) |
| 93 | + |
| 94 | +;;; flymake-csslint.el ends herep |
0 commit comments