Configure PHP-mode for Emacs

Source: Internet
Author: User
Tags coding standards

Php-mode is the mode in which Emacs is used to edit PHP source code. It inherits all the features of C-mode, complies with pear coding standards, searches for PHP manuals, complements the code, and class browsing. This section describes how to modify the php-mode.el file and configure the. emacs file to implement the automatic complementing feature of the PHP library function.
1. installation:
The PHP-mode of emaacs22 of Fedora comes with version 1.4. You can download the latest version :1.5from http://php-mode.sourceforge.net. Unzip the package to a location, enter Emacs, and use the M-x byte-compile-file command to compile the php-mode.el source file. Then copy the php-mode.elc to the/usr/share/Emacs/Site-lisp directory,

Ii. emacs file configuration is as follows:
; Load PHP-Mode
(Add-to-list 'Load-path "/usr/share/Emacs/Site-lisp ")
(Require 'php-mode)
; Automatically PHP-mode based on the file extension
(Add-to-list 'auto-mode-alist' ("\. php [34]? \ '\ | \. Phtml \' ". php-mode ))
; When developing a project, the PHP source file uses another extension
(Add-to-list 'auto-mode-alist' ("\. Module \ '". php-mode ))
(Add-to-list 'auto-mode-alist' ("\. inc \ '". php-mode ))
; Auto-completion settings, method 1
(Setq PHP-manual-path "/usr/share/doc/PHP-manual/en/html /")
; Automatic completion settings, method 2
; Method 1: Search for the PHP-manual-path directory every time you fill in the whole time. The speed is slow. You can use method 2.
; First, set the variable PHP-completion to replace PHP-manual-Path

(Setq PHP-completion-file "~ /. Emacs. d/PHP-completion-file ")

(If you do not have PHP-manual, you can download the http://www.php.net/download-docs.php on the PHP official website select your HTML files)

; Then generate PHP-completion-file on the sehll Terminal
; $ CD/usr/share/doc/PHP-manual/en/html
; $ LS-1 function *. html \
; | Sed-E's/^ function \. \ ([-a-zA-Z_0-9] * \) \. html/\ 1 /'\
; | Tr -_\
;> ~ /. Emacs. d/PHP-completion-File
; Note: Before executing this step, you must install the PHP-manual-en package: Yum install PHP-manual-en
; Set the function key of Emacs auto-completion in the Console mode to F9. You do not need to set this key if you use Emacs window mode.
; Because PHP-model only sets the function key M-tab in the window mode.
(Global-set-Key [(F9)] 'php-complete-function)

3. Modify the php-mode.el File
The function key set for PHP-mode auto-completion is m-tab, which has two problems: 1. You can use alt or ESC to input m, if you press Alt + TAB, it will be the same as the window switch key set by the system; 2. If you replace ALT with ESC, it will not be automatically completed, and the prompt "No tags table loaded; try m-x visit-tags-table ", which seems to be the auto-completion function key of C-mode. So you must modify this function key, which is implemented by modifying the php-mode.el file. Open the php-mode.el file and find here:
(Define-key PHP-mode-Map
[(Meta tab)]
'Php-complete-function)
To:
(Define-key PHP-mode-Map
[(Control tab)]
'Php-complete-function)
Save, recompile, and copy the php-mode.elc file to the/usr/share/Emacs/Site-lisp directory.
If you do not modify the php-mode.el file, you can also use the PHP-mode auto-completion feature, but you must use the menu instead of the shortcut key, because you cannot enter M-tab, however, using menus is too slow. After modification, you can use F9 to call the complete function in the Emacs Console mode, and use F9 and C-tab in the Emacs window mode at the same time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.