Saturday 1 May 2010

Making PHP-mode on Emacs 23 Work Properly



So, recently I've been experimenting with emacs (I'm used the usual old propreitary stuff), and much to my surprise, it seems to be working just great! Except with some problems here and there.

One of the problems I've been having is to get PHP-mode to work properly in Emacs 23. Apparently, it used to work properly in previous versions, but then the usual instructions on the net for installing php mode don't work properly.

As per the usual instructions, you should add the following code to the .emacs file in your home directory:
(add-to-list 'load-path "~/path/to/the/el/file/")
(require 'php-mode)


But turns out that Emacs 23 doesn't like that anymore and gives you an error:

Warning (initialization): An error occurred while loading `~/rishi/.emacs':
error: `c-lang-defconst' must be used in a file
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.


To fix that, you're going to need to follow the instructions on this post.

Which essentially states that instead of putting the (require 'php-mode) line you should put this instead:

(autoload 'php-mode "php-mode" "Major mode for editing php code." t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))


Works for me!




Got a question, tip or comment? Send them to beyondteck+question@gmail.com and we'll try to answer it in a blog post!

No comments:

Post a Comment