2009-05-22 131 views
29

我正在使用Emacs 23和php-mode.el 1.5.0。當我有這個在我的.emacs使php-mode(和其他cc模式派生模式)與Emacs兼容23

(require 'php-mode) 

我收到此錯誤信息時,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.

如果我評價(require 'php-mode) Emacs啓動後,我沒有得到任何錯誤消息。

我找到了一個blog entry這表明這個問題是特定於Emacs 23的(也就是說,Emacs 22.x沒有錯誤),但它沒有提供任何解決方案。

我不知道這是否重要,但我使用Mac   OS   X,我使用./configure --with-ns從當前CVS源代碼構建了Emacs。

這裏發生了什麼,或者我該如何修復它?

+0

我使用Emacs 23和`php-mode`附帶Emacs Starter Kit(也是v1.5.0)。有用。你可能在你的.emacs中有一些影響`php-mode`的其他模式。 – 2009-05-22 15:41:54

+0

我已將我的.emacs更改爲「(add-to-list'加載路徑」〜/ elisp「)(要求'php-mode)」,問題依然存在。 – 2009-05-22 17:46:09

回答

51

當我嘗試啓動並運行csharp模式時遇到了同樣的問題。我終於找到了解決辦法時挖成實際的Emacs Lisp文件csharp模式:

;; 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. 

因此,快速和骯髒的修復就擺在你的.emacs是自動加載的擴展,而不是把(require 'php-mode)(load "php-mode")在那裏。毫不費力,

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

我希望這有助於!現在我只需要讓PHP/HTML模式切換的東西工作。祝我好運。