php-beautifier.el is a lightweight extension that integrates PHP source code beautification into Emacs using the PHP_Beautifier tool. It also supports running code through phpcbf to fix coding standard issues.
All Emacs installs are a little different, but the basic outline is this:
- Download the source code and put it somewhere Emacs can find it (probably
~/.emacs.d/) - Add that directory to your
load-pathif it's not yet there:(add-to-list 'load-path "/path/to/dir") - Add
(require 'php-beautifier)somewhere in your~/.emacs.d/init.el
php-beautifier supplies the following customisation options:
php-beautifier-executable-path- The full path to thePHP_Beautifierexecutable. This isphp_beautifierby default.php-beautifier-indent-method- The indentation method to use. Eitherspacesortabs. Default isspaces.
An example configuration with a full path and tab indentation:
(setq php-beautifier-executable-path "/usr/bin/php_beautifier")
(setq php-beautifier-indent-method "tabs")The following options must be set for phpcbf to run:
php-beautifier-phpcbf-path- The full path to thephpcbfexecutable. This isphpcbfby default.php-beautifier-phpcbf-standard- The coding standard to use withphpcbf. This isnilby default and must be set forphpcbfto be run.
An example configuration which uses the WordPress coding standard:
(setq php-beautifier-phpcbf-path "/usr/bin/phpcbf")
(setq php-beautifier-phpcbf-standard "WordPress")When using phpcbf the code is still run through php_beautifier first. In
some circumstances this may create some odd results but it usually works.
php-beautifier can either format an entire buffer or a single region. The
php_beautifier tool will only format code contained in a <?php block, so
formatting a region that doesn't contain one will not work.
Interactive Commands
php-beautifier-format-region- Format the current region and replace it with formatted code.php-beautifier-format-buffer- Format the current buffer and replace its contents with formatted code.
To run unit tests you'll need Cask installed.
The following command will run all tests:
cask exec ert-runnerReleased under the GPLv3. See COPYING for the full licence.