PHP syntax check as you type with Emacs

For those who have to code in PHP, there’s a nice feature in Emacs that makes your coding horror times less stressing and helps you avoid typos and similar dumb errors.

Emacs 22.1 comes with flymake mode, a nice tool that makes syntax checking while you type out the file by highlighting the lines with errors and displays the error messages.

You can enable flymake to check PHP syntax by adding the following code on your .emacs or whatever Emacs customizations file you use:

;; Flymake PHP Extension (require 'flymake) (unless (fboundp 'flymake-php-init) (defun flymake-php-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "php" (list "-f" local-file "-l"))))) (let ((php-ext-re "\.php[345]?\'") (php-error-re "\(?:Parse\|Fatal\) error: \(.\) in \(.\) on line \([0-9]+\)")) (unless (assoc php-ext-re flymake-allowed-file-name-masks) (add-to-list 'flymake-allowed-file-name-masks (list php-ext-re 'flymake-php-init 'flymake-simple-cleanup 'flymake-get-real-file-name)) (add-to-list 'compilation-error-regexp-alist-alist (list 'compilation-php php-error-re 2 3 nil nil)) (add-to-list 'compilation-error-regexp-alist 'compilation-php) (add-to-list 'flymake-err-line-patterns (list php-error-re 2 3 nil 1)))) ;; add php flymake support (add-hook 'php-mode-hook (lambda () (flymake-mode t)))

Its very nice to have on the fly syntax checking.

Share:
  • Digg
  • del.icio.us
  • Technorati
  • Reddit
  • StumbleUpon
  • Facebook
  • Meneame
  • FriendFeed
  • Identi.ca
  • Twitter
  • Google Bookmarks

Related posts:

  1. How to install PHP PDO extensions on Debian Lenny
  2. Identica mode for Emacs update: support for any Laconica server
  3. 3 methods on how to backup your Emacs file
  4. Back to blogging from Emacs
  5. Emacs tip: How to edit multiple files on several directories in less than a minute

You can leave a response, or trackback from your own site.

One Response to “PHP syntax check as you type with Emacs”

  1. BadGirl13 says:

    For many staff, this can be an eye- opening experience. ,

Leave a Reply


Subscribe to RSS Feed