【已解决】 如何忽视自己主动引入的函数引起的 warning?感谢感谢 🙏

我在配置 org-similarity 的时候使用了 defvaralias 这个函数把 org-similarity-directory 和 org-roam-directory 两个变量绑在一起了,但这导致了每次启动 Emacs 都会有 warning。

请问如何忽略自己主动使用的这个函数导致的 warning 啊?

⛔ Warning (defvaralias): Overwriting value of ‘org-similarity-directory’ by aliasing to ‘org-roam-directory’

GitHub 上搜了一下别人的相关配置,也看了下 Easy Customization,这样写没生效:

(add-to-list 'warning-suppress-types '(defvaralias))

而且导致了另一个 warning,warning-suppress-types 在文档里是一个变量,没搞懂为什么不能这样写 :rofl:

⛔ Warning (initialization): An error occurred while loading ‘/Users/suliveevil/.config/emacs/init.el’:

Symbol's value as variable is void: warning-suppress-types

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

试试 warning-suppress-log-types

报一样的错 :rofl:

Symbol's value as variable is void: warning-suppress-log-types
(with-no-warnings
  (defvaralias .......))
1 个赞

直接赋值不行吗?非要设置成alias

:rofl: 还是 warning

(with-no-warnings
(defvaralias 'org-similarity-directory 'org-roam-directory)
)

不行,org-similarity-directory 赋值之后就写死了,不会像 org-roam-directory 一样读取 .dir-locals.el 里的设置重新赋值。

我需要至少两个文件夹(一个公开,一个私人),这两个变量必须是可以同步动态变化的。

试试把变量设为buffer-local的?最简单的当然就是with-no-warnings

with-no-warnings 不行,我看了下文档,文档里建议用 with-suppressed-warnings。

(with-suppressed-warnings (defvaralias 'org-similarity-directory 'org-roam-directory))

这样写解决了问题。

感谢各位的讨论。

我怀疑是和你的 Emacs 版本有关 :joy:

不至于吧……

我最后是看内置的文档才用的 with-suppressed-warnings

 -- Special Form: with-no-warnings body...
     In execution, this is equivalent to ‘(progn BODY...)’, but the
     compiler does not issue warnings for anything that occurs inside
     BODY.

     We recommend that you use ‘with-suppressed-warnings’ instead, but
     if you do use this construct, that you use it around the smallest
     possible piece of code to avoid missing possible warnings other
     than one you intend to suppress.