【问题标题】:Making php-mode (and other cc-mode derived modes) compatible with Emacs 23使 php-mode(和其他 cc-mode 派生模式)与 Emacs 23 兼容
【发布时间】:2009-05-22 14:10:45
【问题描述】:

我正在使用 Emacs 23 和 php-mode.el 1.5.0。当我在我的.emacs 中有这个时:

(require 'php-mode)

我在 Emacs 启动时收到此错误消息:

警告(初始化):加载`/Users/kdj/.emacs'时出错:

错误:`c-lang-defconst' 必须在文件中使用

为确保正常运行,您应该调查并删除 初始化文件中的错误原因。启动 Emacs `--debug-init' 选项来查看完整的错误回溯。

如果我在 Emacs 启动后评估 (require 'php-mode),我不会收到任何错误消息。

我找到了blog entry,它表明这个问题是 Emacs 23 特有的(即 Emacs 22.x 没有错误),但它没有给出任何解决方案。

我不知道这是否重要,但我使用的是 Mac OS X,并且我使用 ./configure --with-ns 从当前的 CVS 源构建 Emacs。

这里发生了什么,和/或我该如何解决?

【问题讨论】:

  • 我使用 Emacs 23 和 php-mode 附带 Emacs Starter Kit(也是 v1.5.0)。有用。您的 .emacs 中可能还有其他一些影响 php-mode 的模式。
  • 我已将我的 .emacs 更改为 "(add-to-list 'load-path "~/elisp") (require 'php-mode)",但问题仍然存在。跨度>
  • 你能把你的 dotmacs 放在网上的某个地方吗?
  • 如上所述,当我的 .emacs 仅包含以下两行时会出现问题: (add-to-list 'load-path "~/elisp") (require 'php-mode)跨度>

标签: emacs php-mode cc-mode


【解决方案1】:

我在尝试启动和运行 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.

因此,放入 .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 模式切换的东西工作。祝我好运。

【讨论】:

  • 派对迟到了,但非常感谢。我在 Linux 上没有问题,但在 Windows 上,我遇到了同样的错误,因为 nxhtml 会自行自动加载很多东西。我删除了我的 cc-*.elc 文件,错误消失了。
  • 谢谢。我在使用 proto-mode (code.google.com/p/protobuf/source/browse/trunk/editors/…) 时遇到了同样的问题,这解决了它。
【解决方案2】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 2011-05-04
    • 2012-12-02
    • 2016-12-16
    • 2013-07-20
    • 1970-01-01
    • 2020-04-26
    相关资源
    最近更新 更多