Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off php-indent warning in Emacs

When editing a PHP file with PHP code and HTML markup in Emacs, I continue to get the warning:

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.

which pops up at the bottom of my wiindow and takes up half of my editing screen. How do I turn this off?

I know there are various "add-ons" and modes that you can add to make Emacs format PHP + HTML nicely but I just want to turn the warning off. How can I do so?

EDIT:

Here is a portion of the php-mode.el file where the above error seems to be coming from:

(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)))
like image 838
UserIsStuck Avatar asked Oct 02 '22 09:10

UserIsStuck


1 Answers

Grepping the Emacs source code, I do not find that message anywhere. It is probably coming from some other code that you load from your init file.

Check the libraries that you load -- grep them for the message. That will give you an idea how to inhibit the message. It depends how it is created etc.

You can probably advise (defadvice) the function that issues the message, for instance, but you might have to use the advice to replace the function's code by similar code that does not issue the message.

But find the culprit code first. There might be an easy way to inhibit the message, such as a user option.

UPDATE ---

OK, so the function issuing the warning is lwarn. Right away, you can, at least as a workaround, customize option warning-minimum-level and possibly warning-minimum-log-level, to inhibit the warning. But that will also inhibit other warnings of the same level.

The function that calls lwarn is php-check-html-for-indentation, and it calls it unconditionally. Search the code for calls to php-check-html-for-indentation, to see if perhaps that function is called conditionally. With luck there is a condition (perhaps even a user option) you can set or change that will inhibit php-check-html-for-indentation from being called.

If inhibiting php-check-html-for-indentation would not be the right thing, because of other stuff it does besides warn, then your best approach is to advise php-check-html-for-indentation, essentially redefining it as is, but without the call to lwarn. To do that, your defadvice for php-check-html-for-indentation would reuse the original definition, but without the call to lwarn and without any ad-do-it. See the Elisp manual, nodes Advising Functions and Around Advice.

like image 142
Drew Avatar answered Oct 13 '22 03:10

Drew