Drupal mode maintained by arnested
This documentation needs work. See "Help improve this page" in the sidebar.
Overview
A very complete and non-intrusive take on Drupal mode adapting to your Emacs habits. It will not enforce a selection of packages on you, but rather adjust its behavior around your setup. Do you use php-mode-improved instead of php-mode? No problem. Etags instead of gtags? Yes, sure.
It has a very nice file extension independent detection mechanism for whether you are inside a Drupal environment or not, and will apply Drupal specific behavior to your selected major mode if so. See the project's home page for a more complete list of features and usage.
Instead of documenting every aspect of this mode, this guide will focus on a specific state-of-the-art set of packages that reveals the full potential of this mode.
Install from within Emacs: M-x package-install drupal-mode.
Project homepage: github.com/arnested/drupal-mode
Example configuration
The goal with this setup is to get:
- Full syntax highlighting in PHP files using ejmr/php-mode with adjustments that adheres to Drupal's coding standard.
- Auto completion of PHP functions and your source tree.
- See argument list for function at point in echo area using El Doc. For both PHP and your source tree.
- Browse available hooks provided by Drupal core and contrib modules and insert implementation templates based on your module name.
- Real-time reporting of PHP syntax errors and Drupal's coding standard errors using Flycheck.
- Auto-insertion of boilerplate content in .info, .module, .install and .test files.
System wide installations
Required utilities and packages that should be available from the command line.
GNU Global source code tagging system
See own page on GNU Global setup for Drupal.
Its benefit over Etags in this mode is vast for larger projects. If its bug affects you, its worth the while applying a workaround for it.
If you choose to install Drush utilities for Emacs users, this mode may continuously update the tags definitions every time files are saved. (Needs to be configured.)
PHP CodeSniffer with sniffer from Coder module
See Coder/PHP CodeSniffer installation instructions for a complete guide. Quick version:
$ sudo pear install PHP_CodeSniffer
Download and install the Coder module somewhere project independent and symlink its sniffer to PHP CodeSniffer's Standards directory:
$ sudo ln -sf /global/path/to/coder/coder_sniffer/Drupal $(pear config-get php_dir)/PHP/CodeSniffer/Standards/
Emacs packages
These packages should be installed from within Emacs, either by M-x package-install RET <package-name> or by M-x package-list-packages and then selecting packages manually. Make sure you have setup ELPA as described in Emacs.
php-mode– De facto mode for PHP.php-extras– Provides auto-completion source and Eldoc documentation for PHP functions.auto-complete– Auto completion framework.ggtags– GNU Global front-end.js2-mode– Preferred over js3-mode due to wider support/dependency for it.ac-js2– Auto-complete source for js2-mode.flycheck– Real-time syntax and standard checking.drupal-mode– What this is all about.
Emacs configuration
This should go in your ~/.emacs
Auto completion of source code in-line
(require 'auto-complete)
(require 'auto-complete-config)
(ac-config-default)
GNU Global front-end and a workaround in Drupal mode for making Eldoc work with it.
(require 'ggtags)
;; @see https://github.com/arnested/drupal-mode/issues/48
(setq drupal-get-function-args t)
Enable Flycheck in Drupal mode only for PHP files.
(add-hook 'drupal-mode-hook
'(lambda ()
(when (apply 'derived-mode-p drupal-php-modes)
(flycheck-mode t)
)))
Auto-insertion of boilerplate code
(add-hook 'find-file-hook 'auto-insert)
Further customization
Available settings for this Drupal mode can be found by
M-x customize-group RET drupal
For instance, if you also install the sniffer available in the DrupalPractice project, you need to set drupal/phpcs-standard to "Drupal,DrupalPractice" (No space).
The final result
Screenshots
They don't give you the right feel of the features in this mode, but give you an idea what this is all about:
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion



