/.emacs.d/el-get/nxhtml/related/flymake-css.el

https://bitbucket.org/shuangxinyu/emacspack
Lisp | 161 lines | 86 code | 22 blank | 53 comment | 5 complexity | ecfabdc4dc6fe14a573a5bafb4fc29e8 MD5 | raw file
  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. (require 'flymake)
  48. (require 'xml)
  49. (defcustom flymake-allowed-css-file-name-masks '(("\\.css\\'" flymake-css-init))
  50. "Filename extensions that switch on js syntax checks."
  51. :type '(repeat (list (regexp :tag "File name regexp")
  52. (function :tag "Init function")
  53. (choice (const :tag "No cleanup function" nil)
  54. (function :tag "Cleanup function"))))
  55. :group 'flymake)
  56. (defvar flymake-css-err-line-pattern-re '(("^file:\\([^:]+\\):\\([^:]+\\):\\(.*\\)" 1 2 nil 3))
  57. "Regexp matching CSS error messages")
  58. (defcustom flymake-css-validator-jar "~/bin/css-validator.jar"
  59. "Full path to css-validor.jar file.
  60. You need the css-validator.jar and some other files for flymake
  61. for CSS to work. The instructions below tell you how to get and
  62. install it. The instructions are copied from
  63. http://www.emacswiki.org/emacs/FlymakeCSS
  64. Get http://www.w3.org/QA/Tools/css-validator/css-validator.jar
  65. create a directory named ‘lib’ in the same directory. Copy to the
  66. ‘lib’ dir the following jars:
  67. * commons-collections-3.2.1.jar
  68. * jigsaw.jar
  69. * velocity-1.6.1.jar
  70. * xml-apis.jar
  71. * commons-lang-2.4.jar
  72. * tagsoup-1.2.jar
  73. * xercesImpl.jar
  74. From:
  75. URL `http://jigsaw.w3.org/Distrib/jigsaw_2.2.6.tar.gz'
  76. URL `http://www.apache.org/dist/commons/collections/binaries/commons-collections-3.2.1-bin.tar.gz'
  77. URL `http://www.apache.org/dist/commons/lang/binaries/commons-lang-2.4-bin.tar.gz'
  78. URL `http://www.apache.org/dist/velocity/engine/1.6.1/velocity-1.6.1.tar.gz'
  79. URL `http://www.apache.org/dist/xerces/j/Xerces-J-bin.2.9.1.tar.gz'
  80. URL `http://home.ccil.org/~cowan/XML/tagsoup/tagsoup-1.2.jar'
  81. Test validating some CSS file by running:
  82. java -jar css-validator.jar file:somecssfile.css"
  83. :type 'file
  84. :group 'flymake)
  85. ;;(setq flymake-css-validator-jar "c:/dl/programs/css-valid/css-validator.jar")
  86. (defun flymake-css-init ()
  87. (let* ((temp-file (flymake-init-create-temp-buffer-copy
  88. 'flymake-create-temp-inplace))
  89. (local-file (file-relative-name
  90. temp-file
  91. (file-name-directory buffer-file-name))))
  92. (unless (file-exists-p flymake-css-validator-jar)
  93. (error "Can't find css-validator.jar: %s\n\nPlease customize option flymake-css-validator-jar\n"
  94. flymake-css-validator-jar))
  95. (list "java"
  96. (list "-jar" flymake-css-validator-jar
  97. "-output" "gnu"
  98. (concat "file:" local-file)))))
  99. ;;;###autoload
  100. (defun flymake-css-load ()
  101. (dolist (rec flymake-allowed-css-file-name-masks)
  102. (add-to-list 'flymake-allowed-file-name-masks rec))
  103. (dolist (rec flymake-css-err-line-pattern-re)
  104. (add-to-list 'flymake-err-line-patterns rec)))
  105. ;;(defun flymake-make-overlay (beg end tooltip-text face mouse-face)
  106. (defadvice flymake-make-overlay (before
  107. flymake-css-ad-flymake-make-overlay
  108. activate
  109. compile)
  110. (ad-set-arg 2 (xml-substitute-numeric-entities (ad-get-arg 2))))
  111. ;; Fix-me: remove when this has been giving its proper place in Emacs.
  112. (eval-when-compile
  113. (unless (fboundp 'xml-substitute-numeric-entities)
  114. (message "Use Emacs 22 workaround for newsticker--decode-numeric-entities")
  115. (defun xml-substitute-numeric-entities (string)
  116. "Decode SGML numeric entities by their respective utf characters.
  117. This is just a copy of the function in newst-backen.el for Emacs
  118. 22 users.
  119. This function replaces numeric entities in the input STRING and
  120. returns the modified string. For example \"*\" gets replaced
  121. by \"*\"."
  122. (if (and string (stringp string))
  123. (let ((start 0))
  124. (while (string-match "&#\\([0-9]+\\);" string start)
  125. (condition-case nil
  126. (setq string (replace-match
  127. (string (read (substring string
  128. (match-beginning 1)
  129. (match-end 1))))
  130. nil nil string))
  131. (error nil))
  132. (setq start (1+ (match-beginning 0))))
  133. string)
  134. nil))
  135. ))
  136. ;;(eval-after-load 'css-mode (flymake-css-load))
  137. (provide 'flymake-css)
  138. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  139. ;;; flymake-css.el ends here