Configuring Emacs

This short snippet will extend the php-mode in Emacs to follow drupals coding style. Add this to your $HOME/.emacs:

(defun drupal-mode ()
  (interactive)
  (php-mode)
  (setq c-basic-offset 2)
  (setq indent-tabs-mode nil)
  (setq fill-column 78)
  (c-set-offset 'case-label 2)
  (c-set-offset 'arglist-close 0))
  (c-set-offset 'arglist-intro 2)

(add-to-list 'auto-mode-alist '("/drupal.*\\.\\(php\\|module\\|inc\\|test\\|install\\)$" . drupal-mode))
(add-to-list 'auto-mode-alist '("/drupal.*\\.info" . conf-windows-mode))

This will automatically set you in drupal-mode if you load a .php, .module or .inc file from beneath a drupal* directory. You may also manually select drupal mode by hitting M-x drupal-mode.

Additional Features

gengel - March 14, 2008 - 00:39

Any way to make emacs indent array items in an array( ) declaration the way Drupal tends to keep them? Right now they look like:

return array(
             'index' => 'value',
);

When they ought to look like:

return array(
  'index' => 'value',
);

adding this to the

alaa - March 26, 2008 - 12:10

adding this to the indentation rules should do the trick

(c-set-offset 'arglist-intro 2)

http://www.manalaa.net

This combo will also work:

mechfish - July 20, 2008 - 15:38

(c-set-offset 'arglist-intro +)  ;this value is already set by default in my emacs
(setq c-basic-offset 2) ;this is redundant with the recommended code, above

I don't know why the original poster had a problem, since my setup works by default.

conf-windows-mode for .info files

dmhouse - August 15, 2008 - 10:03

The following will also enable conf-windows-mode for .info files inside drupal.* folders:

(add-to-list 'auto-mode-alist '("/drupal.*\\.info" . conf-windows-mode))

Add install files to auto-mode-alist

roy smith - August 24, 2008 - 12:38

You might want to turn this on for install files too:

(add-to-list 'auto-mode-alist '("/drupal.*\\.\\(php\\|module\\|inc\\|test\\|install\\)$" . drupal-mode))

Roy Smith

 
 

Drupal is a registered trademark of Dries Buytaert.