2009-05-22 11 views
29

Utilizzo Emacs 23 e php-mode.el 1.5.0. Quando ho questo nel mio .emacs:Modalità php (e altre modalità derivate in cc) compatibili con Emacs 23

(require 'php-mode) 

io ottenere questo messaggio di errore quando si avvia Emacs:

Warning (initialization): An error occurred while loading `/Users/kdj/.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.

Se valuto (require 'php-mode) dopo l'avvio di Emacs, non ho ricevuto alcun messaggio di errore.

Ho trovato un blog entry che indica che questo problema è specifico di Emacs 23 (ovvero, non vi è alcun errore con Emacs 22.x), ma non fornisce alcuna soluzione.

Non so se questo è importante, ma sto usando Mac   OS   X e ho creato Emacs dalle sorgenti CVS correnti, usando ./configure --with-ns.

Cosa sta succedendo qui e/o come posso risolverlo?

+0

Uso Emacs 23 e 'php-mode' spediti con Emacs Starter Kit (anche v1.5.0). Funziona. Potresti avere alcune altre modalità nel tuo .emacs che effettuano 'php-mode'. –

+0

Ho modificato il mio .emacs in "solo" (add-to-list 'load-path "~/elisp") (richiede' php-mode) "e il problema persiste. –

+0

Puoi mettere i tuoi dotemac da qualche parte online? –

risposta

51

Mi sono imbattuto nello stesso problema quando cercavo di far funzionare la csharp-mode. Ho finalmente trovato la soluzione quando scavare nel file effettivo Emacs Lisp per csharp-mode:

;; This code doesn't seem to work when you compile it, then 
;; load/require in the Emacs file. You will get an error (error 
;; "`c-lang-defconst' must be used in a file") which happens because 
;; cc-mode doesn't think it is in a buffer while loading directly 
;; from the init. However, if you call it based on a file extension, 
;; it works properly. Interestingly enough, this doesn't happen if 
;; you don't byte-compile cc-mode. 

Quindi, la soluzione rapida e sporca di mettere nel vostro .emacs è quello di caricamento automatico su estensione e non mettere (require 'php-mode) o (load "php-mode") lì dentro. Senza ulteriori indugi,

(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)) 

Spero che questo aiuta! Ora ho solo bisogno di far funzionare la modalità PHP/HTML. Augurami buona fortuna.

+0

Impressionante! Questo funziona perfettamente. –

+0

funziona anche per me – Matt

+0

In ritardo per la festa, ma grazie mille per questo. Non ho un problema su Linux, ma su Windows, stavo ottenendo lo stesso errore, dal momento che nxhtml carica automaticamente un sacco di cose da solo. Ho cancellato i miei file cc - *. Elc e gli errori sono andati via. – monksp