当我执行C-h f
orC-h v
时,Help 会告诉我符号是在哪个文件中定义的,或者它将从哪里自动加载。如何以编程方式找到相同的信息?
问问题
738 次
2 回答
9
一些挖掘表明
(find-lisp-object-file-name object type)
应该做的伎俩。举个例子:
(find-lisp-object-file-name 'goto-line 'function)
;; => "/usr/local/Cellar/emacs/24.3/share/emacs/24.3/lisp/simple.el"
编辑:我是如何发现这些信息的:
首先,我确实C-h k C-h f
要弄清楚什么C-h f
是必然的。结果是describe-function
,所以让我们C-h f describe-function
看看它的来源。我注意到它本质上是一个交互式包装器describe-function-1
,所以我跳到了源代码。里面有很多东西,但相关的行是:
(file-name (find-lisp-object-file-name function def))
揭示这find-lisp-object-file-name
是用于在内部完成这项工作的函数。
于 2013-08-10T22:53:49.767 回答
2
添加到詹姆斯波特的答案
;;; run from: emacs -q
(require 'cl) ; for incf
(print (list
;; goto-line is a function defined in simple.el
(find-lisp-object-file-name 'goto-line (symbol-function 'goto-line))
;; print is a function defined in C
(find-lisp-object-file-name 'print (symbol-function 'print))
;; rx is an autoload from rx.el
(find-lisp-object-file-name 'rx (symbol-function 'rx))
;; incf is an alias for cl-incf defined in cl.el
(find-lisp-object-file-name 'incf (symbol-function 'incf))
;; cl-incf is defined in cl-lib.el
(find-lisp-object-file-name 'cl-incf (symbol-function 'cl-incf))))
;; => ("c:/run/Emacs/lisp/simple.el" C-source
;; "c:/run/Emacs/lisp/emacs-lisp/rx.el" "c:/run/Emacs/lisp/emacs-lisp/cl.el"
;; "c:/run/Emacs/lisp/emacs-lisp/cl-lib.el")
(print (list
;; print-circle is a variable defined in C
(find-lisp-object-file-name 'print-circle 'defvar)
;; indent-line-function is a variable defined in indent.el
(find-lisp-object-file-name 'indent-line-function 'defvar)))
;; => (C-source "c:/run/Emacs/lisp/indent.el")
于 2013-08-11T02:25:36.153 回答