Elisp提供了 documentation
函数可以用来获取另一个函数的docstring,然而可惜它是不能通过 setf
修改的:
(defun foo ()
"Old Docstring")
(documentation 'foo)
;; =>"Old Docstring"
(fset (documentation 'foo) "New Docstring")
;; Debugger entered--Lisp error: (wrong-type-argument symbolp "Old Docstring")
不过有一个比较hack的方法,就是修改symbol的 function-documentation
属性. 它的优先级要高于函数本身存储的docstring
(put 'foo 'function-documentation "New Docstring")
(documentation 'foo)
;; =>"New Docstring"