如何在Emacs中关闭PHP缩进警告

5

当我在Emacs中编辑一个包含PHP代码和HTML标记的PHP文件时,我一直收到警告:

Warning (php-indent):
        Indentation fails badly with mixed HTML and PHP.
        Look for an Emacs Lisp library that supports "multiple
        major modes" like mumamo, mmm-mode or multi-mode.

在我的窗口底部弹出了一个窗口,占据了编辑屏幕的一半。我该如何关闭它?我知道有各种“add-ons”和模式可以添加到Emacs中,使其能够很好地格式化PHP + HTML,但是我只想关闭警告。我该怎么办?
编辑:
以下是php-mode.el文件的一部分,似乎上述错误来自此处:
(defvar php-completion-table nil
  "Obarray of tag names defined in current tags table and functions know to PHP.")

(defvar php-warned-bad-indent nil)
(make-variable-buffer-local 'php-warned-bad-indent)

;; Do it but tell it is not good if html tags in buffer.
(defun php-check-html-for-indentation ()
  (let ((html-tag-re "</?\\sw+.*?>")
        (here (point)))
    (if (not (or (re-search-forward html-tag-re (line-end-position) t)
                 (re-search-backward html-tag-re (line-beginning-position) t)))
        t
      (goto-char here)
      (setq php-warned-bad-indent t)
      (lwarn 'php-indent :warning
             "\n\t%s\n\t%s\n\t%s\n"
             "Indentation fails badly with mixed HTML and PHP."
             "Look for an Emacs Lisp library that supports \"multiple"
             "major modes\" like mumamo, mmm-mode or multi-mode.")
      nil)))

(defun php-cautious-indent-region (start end &optional quiet)
  (if (or php-warned-bad-indent
          (php-check-html-for-indentation))
      (funcall 'c-indent-region start end quiet)))

(defun php-cautious-indent-line ()
  (if (or php-warned-bad-indent
          (php-check-html-for-indentation))
      (funcall 'c-indent-line)))
3个回答

3
在Emacs源代码中搜索,我没有发现这个消息的任何地方。它可能来自于你从init文件中加载的其他代码。
检查你加载的库——用grep搜索该消息。这将给你一个抑制该消息的想法。这取决于它是如何创建的等等。
你可以建议(defadvice)发出消息的函数,例如,但你可能不得不使用建议通过类似的代码替换函数的代码,以便不发出消息。
但首先要找到罪魁祸首的代码。可能有一种简单的方法来抑制消息,比如用户选项。
更新---
好的,所以发出警告的函数是lwarn。至少作为解决方法,你可以自定义选项warning-minimum-level和可能的warning-minimum-log-level,以抑制警告。但这也会抑制同级别的其他警告。
调用lwarn的函数是php-check-html-for-indentation,并且它无条件地调用它。 搜索代码以查找对php-check-html-for-indentation的调用,看看是否有条件(甚至是用户选项)可以设置或更改,以防止调用php-check-html-for-indentation
如果抑制php-check-html-for-indentation不是正确的方法,因为它还执行其他操作,除了警告之外,那么你最好的方法是建议php-check-html-for-indentation,基本上重新定义它,但没有调用lwarn。为此,php-check-html-for-indentationdefadvice将重用原始定义,但没有调用lwarn和没有任何ad-do-it。请参阅Elisp手册,节点Advising FunctionsAround Advice

警告在/usr/share/emacs/site-lisp/php-mode.el中。我如何检查我加载的库?我只在我的.emacs文件中看到以下设置:(setq diff-switches "-u")(setq frame-title-format (concat "%b - emacs@" (system-name))) - UserIsStuck
据我所知,php-mode.el不是Emacs(即emacs -Q)的一部分。你一定是从其他地方得到它的。尝试使用M-x find-library php-mode命令,它会带你到文件php-mode.el,你可以在其中搜索消息。 - Drew
我已经找到了文件,而且消息在那里。我只是不知道如何关闭这个“功能”。如果需要的话,我可以发布 php-mode.el 文件的内容。 - UserIsStuck
好的,请这样做。不需要整个文件,只需要发出消息的函数。不知道我们能否帮忙,但是如果没有看到代码,就无法提出建议。 - Drew
我在问题中添加了更多细节。谢谢。 - UserIsStuck
1
感谢您的所有帮助,最终我发现我所做的更改没有生效,并在这里找到了解决方案。 - UserIsStuck

1
在调用这两个函数的地方有一个条件语句。打开你的.emacs文件并添加以下行:

(setq php-mode-warn-if-mumamo-off nil)

这样应该就解决了你的问题 :-)


0
借用你那段代码片段中的一行,我放置了。
(setq php-warned-bad-indent t)

在我的.emacs文件中。经过测试,对我有效。

(我简直不敢相信我刚刚发布了一个涉及Lisp的答案。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接