PDA

View Full Version : [Help]highlight php code with emacs23.



haidang001
April 6th, 2011, 05:18 PM
I have ubuntu 10.10 installed emacs (emacs23.1.1).
I found Emacs insteresting, but It cannot work with php-mode (may be that php-mode hasn't been installed). It doesn't highlight php code.

Help me, please. Thank you so much!

johnl
April 6th, 2011, 07:17 PM
Hi,

You can download a php major mode from here: http://sourceforge.net/projects/php-mode/


To install, this is how I would do it:

Extract the 'php-mode.el' to '~/emacs.d/site-lisp/php-mode.el' creating the folders if necessary.

Open your "~/.emacs" (or ~/.emacs.d/init.el) file and add the following:



;; tell emacs that we have some modules in this folder:
(add-to-list 'load-path "~/.emacs.d/site-lisp")
;; use php-mode
(require 'php-mode)
;; use php-mode for .php files
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))


Hope this helps.

haidang001
April 7th, 2011, 05:11 PM
Hi,

You can download a php major mode from here: http://sourceforge.net/projects/php-mode/


To install, this is how I would do it:

Extract the 'php-mode.el' to '~/emacs.d/site-lisp/php-mode.el' creating the folders if necessary.



I 've copied 'php-mode.el' to '~/.emacs.d/site-lisp/php-mode.el' (not '~/emacs.d', I think so). And followed your suggestion, but when I start emacs, it shows this error:


Warning (initialization): An error occurred while loading `/root/.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.
So, I start Emacs with the '--debug-init' (by gnome-terminal). It says:

͂͂͂͂͂Debugger entered--Lisp error: (error "`c-lang-defconst' must be used in a file")
signal(error ("`c-lang-defconst' must be used in a file"))
error("`c-lang-defconst' must be used in a file")
c-define-lang-constant(c-mode-menu ((t cons ["Comment Out Region" comment-region ...] (cons ["Uncomment Region" ... ...] ...))))
require(cc-langs)
eval-buffer(#<buffer *load*<2>> nil "/root/.emacs.d/site-lisp/php-mode.el" nil t) ; Reading at buffer position 4158
load-with-code-conversion("/root/.emacs.d/site-lisp/php-mode.el" "/root/.emacs.d/site-lisp/php-mode.el" nil t)
require(php-mode)
eval-buffer(#<buffer *load*> nil "/root/.emacs" nil t) ; Reading at buffer position 624
load-with-code-conversion("/root/.emacs" "/root/.emacs" t t)
load("~/.emacs" t t)
#[nil "^H\205\264^@ . . . etc (I cannot fully paste this line)
command-line()
normal-top-level()
Could you help me with this bug :(.

haidang001
April 15th, 2011, 04:26 PM
Anyone can help me, please!