简体   繁体   English

使php模式(和其他cc模式派生模式)与Emacs 23兼容

[英]Making php-mode (and other cc-mode derived modes) compatible with Emacs 23

I am using Emacs 23 and php-mode.el 1.5.0. 我使用的是Emacs 23和php-mode.el 1.5.0。 When I have this in my .emacs : 当我在我的.emacs有这个时:

(require 'php-mode)

I get this error message when Emacs starts: 我在Emacs启动时收到此错误消息:

Warning (initialization): An error occurred while loading `/Users/kdj/.emacs': 警告(初始化):加载`/Users/kdj/.emacs'时出错:

error: `c-lang-defconst' must be used in a file 错误:必须在文件中使用`c-lang-defconst'

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. 使用`--debug-init'选项启动Emacs以查看完整的错误回溯。

If I evaluate (require 'php-mode) after Emacs starts, I don't get any error messages. 如果我在Emacs启动后评估(require 'php-mode) ,我不会收到任何错误消息。

I found a blog entry which indicates that this problem is specific to Emacs 23 (that is, there is no error with Emacs 22.x), but it doesn't give any solutions. 我找到了一个博客条目 ,表明此问题是Emacs 23特有的(也就是说,Emacs 22.x没有错误),但它没有提供任何解决方案。

I don't know if this matters, but I'm using Mac OS X, and I built Emacs from the current CVS sources, using ./configure --with-ns . 我不知道这是否重要,但我使用的是Mac OS X,我使用./configure --with-ns从当前的CVS源构建了Emacs。

What's going on here, and/or how I can fix it? 这里发生了什么,和/或我如何解决它?

I ran into the same problem when trying to get the csharp-mode up and running. 我试图让csharp模式启动并运行时遇到了同样的问题。 I finally found the solution when digging into the actual Emacs Lisp file for csharp-mode: 当我深入研究csharp-mode的实际Emacs Lisp文件时,我终于找到了解决方案:

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

So, the quick and dirty fix to put in your .emacs is to auto load on extension and not put (require 'php-mode) or (load "php-mode") in there. 因此,放入.emacs的快速和脏修复是在扩展上自动加载而不是放入(require 'php-mode)(load "php-mode") Without further ado, 无需再费周折,

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

I hope this helps! 我希望这有帮助! Now I just need to get the PHP/HTML mode switching stuff working. 现在我只需要让PHP / HTML模式切换工作。 Wish me luck. 祝我好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM