From 13b2fff6ef2e04c546c705ac1d9f282e2f4f9184 Mon Sep 17 00:00:00 2001 From: Thomas Fini Hansen Date: Mon, 3 Mar 2014 22:13:58 +0100 Subject: [PATCH 1/4] Use flycheck-add-next-checker. Properly chain into the checker chain for js/css modes. Also check info files. Closes #41. --- drupal/flycheck.el | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drupal/flycheck.el b/drupal/flycheck.el index 84d5da1..5f2d948 100644 --- a/drupal/flycheck.el +++ b/drupal/flycheck.el @@ -28,19 +28,11 @@ (require 'flycheck) (require 'drupal/phpcs) -(defcustom drupal/flycheck-phpcs-js-and-css t - "When Non-nil, override Flycheck to use PHPCS for checking CSS and JavaScript files instead of the checkers configured for css-mode and js-mode." - :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)) - drupal/phpcs-standard) - ;; Set the coding standard to "Drupal" (we checked that it is - ;; supported above. + (when (and drupal-mode drupal/phpcs-standard) + ;; Set the coding standard to "Drupal" (phpcs.el has checked that + ;; it's supported). (setq flycheck-phpcs-standard drupal/phpcs-standard) ;; Flycheck will also highlight trailing whitespace as an @@ -50,11 +42,11 @@ (add-hook 'drupal-mode-hook #'drupal/flycheck-hook) -(flycheck-define-checker css-js-phpcs - "Check CSS and JavaScript using PHP_CodeSniffer. +(flycheck-define-checker drupal-phpcs + "Check non-PHP Drupal files using PHP_CodeSniffer. -PHP_CodeSniffer can be used to check non-PHP files, as exemplified by the -Drupal code sniffer. +The Drupal standard includes checks for non-PHP files, this +checker runs those. See URL `http://pear.php.net/package/PHP_CodeSniffer/'." :command ("phpcs" "--report=emacs" @@ -72,11 +64,19 @@ See URL `http://pear.php.net/package/PHP_CodeSniffer/'." (warning line-start (file-name) ":" line ":" column ": warning - " (message) line-end)) - :modes (css-mode js-mode) + ;; We'd prefer to just check drupal-mode, but flycheck global mode + ;; finds the checker before we get a chance to set drupal-mode. :predicate (lambda () - (and drupal/flycheck-phpcs-js-and-css (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes))))) - -(add-to-list 'flycheck-checkers 'css-js-phpcs) + (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes drupal-info-modes)))) + +;; Append our custom checker. +(add-to-list 'flycheck-checkers 'drupal-phpcs t) +;; Add our checker as next-checker to checkers of all supported modes. +(let ((modes (append drupal-css-modes drupal-js-modes drupal-info-modes))) + (dolist (checker (flycheck-defined-checkers)) + (dolist (mode (flycheck-checker-modes checker)) + (if (memq mode modes) + (flycheck-add-next-checker checker 'drupal-phpcs))))) (provide 'drupal/flycheck) From 135c5f669e9ac8bc11ae8e21f18b0133f79dafc7 Mon Sep 17 00:00:00 2001 From: joddie Date: Tue, 4 Mar 2014 01:12:32 +0000 Subject: [PATCH 2/4] Add interface with gtags via `ggtags.el' --- drupal-mode.el | 1 + drupal/ggtags.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 drupal/ggtags.el diff --git a/drupal-mode.el b/drupal-mode.el index c8cb7a8..2987341 100644 --- a/drupal-mode.el +++ b/drupal-mode.el @@ -774,6 +774,7 @@ mode-hook." (eval-after-load 'autoinsert '(require 'drupal/autoinsert)) (eval-after-load 'etags '(require 'drupal/etags)) (eval-after-load 'gtags '(require 'drupal/gtags)) +(eval-after-load 'ggtags '(require 'drupal/ggtags)) (eval-after-load 'ispell '(require 'drupal/ispell)) (eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs)) (eval-after-load 'flycheck '(require 'drupal/flycheck)) diff --git a/drupal/ggtags.el b/drupal/ggtags.el new file mode 100644 index 0000000..bbb0c34 --- /dev/null +++ b/drupal/ggtags.el @@ -0,0 +1,62 @@ +;;; drupal/ggtags.el --- Drupal-mode support for ggtags.el + +;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen + +;; Author: Arne Jørgensen + +;; 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 . + +;;; Commentary: + +;; Enable drupal-mode support for gtags. + +;;; Code: + +(require 'ggtags) + +(defvar drupal/ggtags-global-command (executable-find "global") + "Name of the GNU GLOBAL `global' executable. +Include path to the executable if it is not in your $PATH.") + +(defun drupal/ggtags-enable () + "Setup rootdir for gtags." + (let ((dir (locate-dominating-file (or buffer-file-name default-directory) "GTAGS"))) + (when dir + (ggtags-mode 1) + ;; Connect `drupal-symbol-collection' to `ggtags-mode' + ;; completion + (setq drupal-symbol-collection + (lambda () (all-completions "" ggtags-completion-table))) + (setq drupal-get-function-args #'drupal/ggtags-get-function-args)))) + +(defun drupal/ggtags-get-function-args (symbol &optional version) + "Get function arguments from GNU GLOBAL." + (when (and (boundp 'ggtags-project-root) + (file-exists-p (expand-file-name "GTAGS" ggtags-project-root))) + (with-temp-buffer + (ignore-errors + (call-process drupal/ggtags-global-command nil t nil "-x" symbol) + (goto-char (point-min)) + (search-forward-regexp "[^(]*(\\(.*\\))[^)]*" nil t) + (match-string-no-properties 1))))) + +(add-hook 'drupal-mode-hook #'drupal/ggtags-enable) + + + +(provide 'drupal/ggtags) + +;;; drupal/ggtags.el ends here From bef3447608599d1c944d52abec01f9879bdc19c6 Mon Sep 17 00:00:00 2001 From: joddie Date: Tue, 4 Mar 2014 01:13:35 +0000 Subject: [PATCH 3/4] Add menu items for function & hook templates --- drupal-mode.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drupal-mode.el b/drupal-mode.el index c8cb7a8..c0967c1 100644 --- a/drupal-mode.el +++ b/drupal-mode.el @@ -387,6 +387,12 @@ of the project)." (define-key drupal-mode-map [menu-bar drupal manual] '("Drupal Mode manual" . drupal-mode-manual)) +(define-key drupal-mode-map + [menu-bar drupal insert-hook] + '("Insert hook implementation" . drupal-insert-hook)) +(define-key drupal-mode-map + [menu-bar drupal insert-function] + '("Insert function template" . drupal-insert-function)) (define-key drupal-mode-map [menu-bar drupal search-documentation] '(menu-item "Search documentation" drupal-search-documentation From 60b231a125d546528c418a4048ae4815133fde7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Wed, 12 Mar 2014 14:35:27 +0100 Subject: [PATCH 4/4] Bumped version to 0.5.0. --- drupal-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drupal-mode.el b/drupal-mode.el index 69ff5b6..998a68b 100644 --- a/drupal-mode.el +++ b/drupal-mode.el @@ -5,7 +5,7 @@ ;; Author: Arne Jørgensen ;; URL: https://github.com/arnested/drupal-mode ;; Created: January 17, 2012 -;; Version: 0.4.1 +;; Version: 0.5.0 ;; Package-Requires: ((php-mode "1.5.0")) ;; Keywords: programming, php, drupal