代码之家  ›  专栏  ›  技术社区  ›  Peter Coulton

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

  •  29
  • Peter Coulton  · 技术社区  · 6 年前

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

    (require 'php-mode)
    

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

    初始化文件中错误的原因。用 “--debug init”选项以查看完整的错误回溯。

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

    blog entry 这表明这个问题特定于Emacs 23(也就是说,Emacs 22.x没有错误),但它没有给出任何解决方案。

    我不知道这是否重要,但我正在使用MacOSX,我使用当前的CVS源代码构建了Emacs ./configure --with-ns

    这里发生了什么,和/或我如何修复它?

    2 回复  |  直到 7 年前
        1
  •  51
  •   Peter Mortensen icecrime    7 年前

    我在尝试启动并运行csharp模式时遇到了同样的问题。在深入研究csharp模式的实际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模式切换功能正常工作。祝我好运。

        2
  •  1
  •   Bertrand Marron    15 年前
    推荐文章