修改现有 Emacs Lisp 函数的文档字符串槽

Modifying docstring slot of an existing Emacs Lisp function

出于各种原因,我不得不使用 Emacs git master 进行开发。在这个版本中,我经常收到很多形式为

的警告
No docstring slot for tags-lazy-completion-table
No docstring slot for etags--xref-backend
No docstring slot for gnus-intersection
No docstring slot for grep-compute-defaults
...

通常太多了,以至于减慢了我的互动速度。是否可以在不修改其现有主体定义的情况下设置已定义的 Emacs Lisp 函数的文档字符串?

No docstring slot for ... 警告是您的问题,而不是缺少文档字符串(这很正常)。我建议你试试

(setq debug-on-message "\`No docstring slot for")

然后查看回溯,您将(希望)尝试找出哪些包发出此警告以及原因(特别是为什么它只在 Emacs-master 中发出:可能是 Emacs 中的错误- master,或者不兼容......在任何一种情况下,Emacs 维护者都可能想听听它)。

Stefan 已解决您的实际问题,但要回答所述问题:

Is it possible to set the docstring of a an already defined Emacs Lisp function without modifying its existing body definition?

是的,您可以通过 function-documentation 符号 属性。

(put FUNCTIONSYMBOL 'function-documentation VALUE)

在大多数情况下,VALUE 是一个字符串。

参见:

  • C-hig (elisp)Documentation Basics
  • C-hig (elisp)Accessing Documentation