More posts about: emacs, wickedcoolemacs Tags: highlight, php // 26 Comments »
(add-to-list 'load-path "~/elisp") (require 'php-mode)This configures Emacs to automatically recognize files ending in ".php", ".phps", ".php3", ".php4", ".phtml", and ".inc" as PHP files. To associate more extensions with PHP files, add lines like this example to your ~/.emacs:
(add-to-list 'auto-mode-alist '("\\.module$" . php-mode)) (add-to-list 'auto-mode-alist '("\\.inc$" . php-mode)) (add-to-list 'auto-mode-alist '("\\.install$" . php-mode)) (add-to-list 'auto-mode-alist '("\\.engine$" . php-mode))This associates php-mode with the extensions used by Drupal, a PHP framework. When you open a file with the specified extension, it should be highlighted according to PHP syntax. Here are some useful commands:
|TAB||c-indent-command||Indent the current line|
|M-;||comment-dwim||Add a line comment, comments or uncomments the currently-selected region, or does other smart comment-related actions|
|C-c C-f||php-search-documentation||Search the online PHP manual for the current word|
|C-c RET||php-browse-manual||View the online PHP manual|
|C-c .||c-set-style||Change coding style|
|C-M-a, C-M-e||c-beginning-of-defun, c-end-of-defun||Go to the beginning or end of the current function|
|C-M-h||c-mark-function||Select the current function|
|M-a, M-e||c-beginning-of-statement, c-end-of-statement||Go to the beginning or end of the current statement|
|indent-tabs-mode||Set this to nil if you want to insert spaces instead of tabs|
|case-fold-search||Set this to t if you want case-insensitive search.|
|c-basic-offset||Set your tab size or number of spaces used as a basis for indentation|
(defun wicked/php-mode-init () "Set some buffer-local variables." (setq case-fold-search t) (setq indent-tabs-mode nil) (setq fill-column 78) (setq c-basic-offset 2) (c-set-offset 'arglist-cont 0) (c-set-offset 'arglist-intro '+) (c-set-offset 'case-label 2) (c-set-offset 'arglist-close 0)) (add-hook 'php-mode-hook 'wicked/php-mode-init)You can further customize the indentation by moving the point to where the indentation needs improvement and typing C-c C-o (c-set-offset). To try automatic indentation, press C-j (newline-and-indent). If you like that behavior, you can make it the default in php-mode by adding the following line in ~/.emacs: (define-key php-mode-map (kbd "RET") 'newline-and-indent) You may also be interested in M-x show-paren-mode, which shows the matching parenthesis, bracket or brace for the character at point. You can enable it automatically by adding the following line to your ~/.emacs:
(setq show-paren-mode t)It's a good idea to separate PHP and HTML code. This is not only better coding practice, but it also makes developing in Emacs much easier. php-mode focuses on PHP-specific behavior and does not have special support for HTML. Emacs has a number of packages that allow you to work with multiple modes like php-mode and html-helper-mode in a single buffer, but they don't always work, and indentation can be confusing. If you must work with large segments of both PHP and HTML in the same file, check out MultipleModes (http://www.emacswiki.org/cgi-bin/wiki/MultipleModes) for tips.
- 08 July 2009 at 12:07pm
- 90 esquemas de color para Emacs | lobo_tuerto 01 January 2010 at 11:01am
- Emacs and PHP tutorial: php-mode » sacha chua :: enterprise 2.0 … | Coder Online
[...] Emacs está configurado para reconocer ciertas extensiones de archivo y abrir el ...
[...] See the article here: Emacs and PHP tutorial: php-mode » sacha chua :: enterprise ...