branch: elpa/drupal-mode
commit 0b9e5d25b43257f4ec3edbabc4c514d2f5ba30ad
Author: Thomas Fini Hansen <[email protected]>
Commit: Thomas Fini Hansen <[email protected]>
Added basic support for flycheck.
---
drupal-mode.el | 1 +
drupal/flycheck.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
drupal/flymake-phpcs.el | 23 +++----------------
drupal/phpcs.el | 54 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+), 20 deletions(-)
diff --git a/drupal-mode.el b/drupal-mode.el
index 27e91419cf..08434cc5b5 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -682,6 +682,7 @@ mode-hook."
(eval-after-load 'gtags '(require 'drupal/gtags))
(eval-after-load 'ispell '(require 'drupal/ispell))
(eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs))
+(eval-after-load 'flycheck '(require 'drupal/flycheck))
;;;###autoload
(eval-after-load 'pcomplete '(require 'drupal/pcomplete))
;;;###autoload
diff --git a/drupal/flycheck.el b/drupal/flycheck.el
new file mode 100644
index 0000000000..d3075bd801
--- /dev/null
+++ b/drupal/flycheck.el
@@ -0,0 +1,61 @@
+;;; drupal/flymake-phpcs.el --- Drupal-mode support for flymake-phpcs
+
+;; Copyright (C) 2012, 2013 Arne Jørgensen
+
+;; Author: Thomas Fini Hansen <[email protected]>
+
+;; This file is part of Drupal mode.
+
+;; Drupal mode is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+
+;; Drupal mode is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with Drupal mode. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Enable drupal-mode support for flymake-phpcs.
+
+;;; Code:
+
+(require 'drupal/phpcs)
+
+(defcustom drupal/flycheck-phpcs-dont-show-trailing-whitespace t
+ "Non-nil means don't highlight trailing whitespace when flycheck-phpcs is in
use.
+Flycheck-phpcs will also highlight trailing whitespace as an error
+so no need to highlight it twice."
+ :type `(choice
+ (const :tag "Yes" t)
+ (const :tag "No" nil))
+ :group 'drupal)
+
+(defun drupal/flycheck-hook ()
+ "Enable drupal-mode support for flycheck."
+ (when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes
drupal-js-modes))
+ (executable-find "phpcs")
+ drupal/phpcs-standard)
+ ;; Set the coding standard to "Drupal" (we checked that it is
+ ;; supported above.
+ (set (make-local-variable 'flycheck-phpcs-standard) drupal/phpcs-standard)
+
+ ;; Flycheck will also highlight trailing whitespace as an
+ ;; error so no need to highlight it twice.
+ (when drupal/flycheck-phpcs-dont-show-trailing-whitespace
+ (setq show-trailing-whitespace nil))
+ )
+)
+
+(add-hook 'drupal-mode-hook #'drupal/flycheck-hook)
+
+
+
+(provide 'drupal/flycheck)
+
+;;; drupal/flycheck.el ends here
diff --git a/drupal/flymake-phpcs.el b/drupal/flymake-phpcs.el
index 88cb71b4c5..c2f35b13f3 100644
--- a/drupal/flymake-phpcs.el
+++ b/drupal/flymake-phpcs.el
@@ -27,24 +27,7 @@
(require 'flymake)
(require 'flymake-phpcs)
-
-(defcustom drupal/flymake-phpcs-standard
- (ignore-errors
- (let ((standards (with-output-to-string
- (with-current-buffer standard-output
- (call-process (executable-find flymake-phpcs-command)
nil (list t nil) nil "-i")))))
- (when (string-match
- "\\(Drupal[^,
-]*\\)"
- standards)
- (match-string-no-properties 1 standards))))
- "Name of Drupal coding standard rules for PHP CodeSniffer.
-This can either be the name of an installed standard (to see
-installed standards run `phpcs -i') or it can be the file name of
-a standard. Adding file name requires PHP CodeSniffer version
-1.3.4 or newer."
- :link '(url-link :tag "Drupal Code Sniffer"
"http://drupal.org/project/drupalcs")
- :group 'drupal)
+(require 'drupal/phpcs)
(defcustom drupal/flymake-phpcs-dont-show-trailing-whitespace t
"Non-nil means don't highlight trailing whitespace when flymake-phpcs is in
use.
@@ -59,10 +42,10 @@ so no need to highlight it twice."
"Enable drupal-mode support for flymake-phpcs."
(when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes
drupal-js-modes))
(executable-find flymake-phpcs-command)
- drupal/flymake-phpcs-standard)
+ drupal/phpcs-standard)
;; Set the coding standard to "Drupal" (we checked that it is
;; supported above.
- (set (make-local-variable 'flymake-phpcs-standard)
drupal/flymake-phpcs-standard)
+ (set (make-local-variable 'flymake-phpcs-standard) drupal/phpcs-standard)
;; Flymake-phpcs will also highlight trailing whitespace as an
;; error so no need to highlight it twice.
diff --git a/drupal/phpcs.el b/drupal/phpcs.el
new file mode 100644
index 0000000000..fe4cc6fe10
--- /dev/null
+++ b/drupal/phpcs.el
@@ -0,0 +1,54 @@
+;;; drupal/flymake-phpcs.el --- Drupal-mode support for flymake-phpcs
+
+;; Copyright (C) 2012, 2013 Arne Jørgensen
+
+;; Author: Arne Jørgensen <[email protected]>
+
+;; This file is part of Drupal mode.
+
+;; Drupal mode is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+
+;; Drupal mode is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with Drupal mode. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Enable drupal-mode support for flymake-phpcs.
+
+;;; Code:
+
+(defcustom drupal/phpcs-standard
+ ; (ignore-errors
+ (let ((standards (with-output-to-string
+ (with-current-buffer standard-output
+ ;; Flymake uses flymake-phpcs-command, while
+ ;; flycheck just uses the phpcs
+ ;; command. Check for both.
+ (call-process (or (and (boundp
'flymake-phpcs-command) (executable-find flymake-phpcs-command))
(executable-find "phpcs")) nil (list t nil) nil "-i")))))
+ (when (string-match
+ "\\(Drupal[^,
+]*\\)"
+ standards)
+ (match-string-no-properties 1 standards)))
+;)
+ "Name of Drupal coding standard rules for PHP CodeSniffer.
+This can either be the name of an installed standard (to see
+installed standards run `phpcs -i') or it can be the file name of
+a standard. Adding file name requires PHP CodeSniffer version
+1.3.4 or newer."
+ :link '(url-link :tag "Drupal Code Sniffer"
"http://drupal.org/project/drupalcs")
+ :group 'drupal)
+
+
+
+(provide 'drupal/phpcs)
+
+;;; drupal/phpcs.el ends here