You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Emacs:如何仅禁用‘已弃用(deprecated)’类型的启动警告?

解决Emacs第三方包已弃用警告的问题

方法1:全局屏蔽所有已弃用警告

如果确认自身代码不会用到已弃用功能,可直接通过配置屏蔽:deprecated类型的警告:

(setq warning-filter-types '(:deprecated))

该设置会让Emacs不再显示任何已弃用相关警告,包括第三方包和你自己代码的。若临时需要查看这类警告,可执行M-x toggle-warnings切换显示状态。

方法2:仅屏蔽第三方包的已弃用警告

若想保留自身代码的已弃用警告,只过滤第三方包的,可通过自定义警告处理函数实现。以下代码会检查警告来源文件是否在elpa目录(第三方包默认安装位置),若是则忽略:deprecated类型警告:

(defun my-filter-deprecated-warnings (type message level &rest args)
  (unless (and (eq type :deprecated)
               (string-prefix-p (expand-file-name "elpa/" user-emacs-directory)
                                (or (car args) "")))
    (apply #'warn type message level args)))

(setq warning-function #'my-filter-deprecated-warnings)

注意:若你的第三方包安装在其他目录,需修改代码中的"elpa/"为对应路径。

方法3:添加调试开关,按需显示已弃用警告

可设置开关变量,日常使用时屏蔽警告,调试时开启:

(defvar my-show-deprecated-warnings nil
  "是否显示已弃用警告,调试时可设为t")

(defun my-conditional-deprecated-warning (type message level &rest args)
  (if (and (eq type :deprecated)
           (not my-show-deprecated-warnings))
      nil ; 不显示警告
    (apply #'warn type message level args)))

(setq warning-function #'my-conditional-deprecated-warning)

日常保持my-show-deprecated-warnings为nil,需要调试或查看警告时,执行:

(setq my-show-deprecated-warnings t)

重启Emacs或重新加载配置后即可看到已弃用警告。


内容的提问来源于stack exchange,提问作者Ryo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 05:26:00