Next: , Previous: Motion, Up: Top


5 Indentation

PHP mode's indentation settings inherit the defaults set by Emacs C mode, or the rules customized for C mode.1

PHP mode provides indentation settings that follow the PHP PEAR “Coding Standards”2. It has the consequence in PHP mode of making the indentation commands use four spaces, and not tabs. This setting is turned on whenever the file name associated with a buffer includes the string “PEAR”, case insensitive and the file ends in “.php”.

You can force the use of this setting for all files edited with PHP mode by setting php-mode-force-pear to non-nil. Configure the variable with either M-x customize-variable RET php-mode-force-pear RET, or by setting its value in your Emacs initialization file (~/.emacs).

PHP does not appropriately indent HTML tags. See Embedded HTML.

To customize PHP mode's indentation rules, change the following variables.

c-basic-offset
This style variable of C mode controls how many columns in the level of indentation. By default this is 4 spaces in PHP mode (and in C mode).
indent-tabs-mode
Variable of Emacs that determines whether indentation commands should insert the tab character or insert the equivalent number of space characters. In PHP mode, this is set to to nil by default.
tab-width
This variable of Emacs determines how “wide” a tab in the buffer should be considered. This is also traditionally described as setting the distance between “tab stops”. By default, PHP mode does not insert tabs for indentation.
php-mode-force-pear
Use the indentation rules of PHP PEAR for all files opened in PHP mode. See above.

The usual commands for indenting in Emacs3 and Emacs's C mode4: are supported in PHP mode, following the indentation rules of PHP.

TAB
Properly indent current line, even from the middle of the line (c-indent-command).
C-j
Insert text after point to a newline, and properly indent the newline (c-indent-command).
C-M-\
Properly indent each line of region (indent-region).
C-c C-q
Properly indent each line of current top-level function or top-level class (c-indent-defun).

Footnotes

[1] See Customizing Indentation.

[2] http://pear.php.net/manual/en/standards.php

[3] See Indentation Commands.

[4] See Indentation Commands.