草庐IT

php - 如何在 Emacs 中关闭 php-indent 警告

coder 2023-08-11 原文

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

它会在我的窗口底部弹出并占据我编辑屏幕的一半。我该如何关闭它?

我知道您可以添加各种“附加组件”和模式来使 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)))

最佳答案

搜索 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

关于php - 如何在 Emacs 中关闭 php-indent 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20102746/

有关php - 如何在 Emacs 中关闭 php-indent 警告的更多相关文章

  1. ruby - 如何在 Ruby 中顺序创建 PI - 2

    出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

  2. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  3. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  4. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  5. ruby - 如何为 emacs 安装 ruby​​-mode - 2

    我刚刚为fedora安装了emacs。我想用emacs编写ruby。为ruby​​提供代码提示、代码完成类型功能所需的工具、扩展是什么? 最佳答案 ruby-mode已经包含在Emacs23之后的版本中。不过,它也可以通过ELPA获得。您可能感兴趣的其他一些事情是集成RVM、feature-mode(Cucumber)、rspec-mode、ruby-electric、inf-ruby、rinari(用于Rails)等。这是我当前用于Ruby开发的Emacs配置:https://github.com/citizen428/emacs

  6. ruby - 在院子里用@param 标签警告 - 2

    我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?

  7. ruby - 如何在续集中重新加载表模式? - 2

    鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende

  8. ruby-on-rails - active_admin 目录中的常量警告重新声明 - 2

    我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA

  9. ruby - 如何在 Ruby 中拆分参数字符串 Bash 样式? - 2

    我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"

  10. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

随机推荐