[英]Visiting required file from .emacs
Is it possible to visit a mentioned file in require like: 是否可以在require中访问提到的文件,例如:
(require 'key-chord)
For which when clicking on "key-chord" (or some other input than clicking), makes you visit that file? 单击“和弦”(或单击以外的其他输入)时,会导致您访问该文件?
EDIT: Given that we want to visit the file "key-chord.el" 编辑:鉴于我们要访问文件“ key-chord.el”
Put the cursor on whatever is being required, eg the "k" in "key-chord", and do Mx ffap RET RET
. 将光标放在所需的任何地方,例如“ key-chord”中的“ k”,然后执行
Mx ffap RET RET
。 ffap
is an alias for find-file-at-point
, which understands require
, at least in lisp-mode. ffap
是find-file-at-point
的别名,至少在lisp模式下,它理解require
。 I have ffap
bound to Cx f
, because I rarely have use for that key's default binding. 我已经将
ffap
绑定到Cx f
,因为我很少使用该键的默认绑定。
Some Emacs installations don't have the .el files (only the .elc files). 某些Emacs安装没有.el文件(只有.elc文件)。 In Debian/Ubuntu, you need to install a separate package to get them (emacs- version -el, IIRC).
在Debian / Ubuntu中,您需要安装一个单独的软件包来获取它们(emacs- version -el,IIRC)。
locate-library
tells you the file name, and find-file
opens the file in a buffer for editing. find-file
locate-library
告诉您文件名,而find-file
file在缓冲区中打开文件以进行编辑。 (You might want find-file-read-only
if you merely want to inspect it.) (如果您只想检查
find-file-read-only
可能希望find-file-read-only
。)
(find-file (locate-library "key-chord.el" t))
You can turn it into a function, something like this: 您可以将其转换为函数,如下所示:
(defun find-locate-library (lib)
"Visit the source for library LIB in a buffer."
(let ((location (locate-library (concat lib ".el") t)))
(if location
(find-file location)
(message "Could not find library %s" lib)) ))
How to hook this into a viewing or editing buffer is a separate topic. 如何将其连接到查看或编辑缓冲区是一个单独的主题。 I suppose you could amend Elisp mode to make library names clickable, but I cannot tell off-hand how to do that.
我想您可以修改Elisp模式以使库名称可单击,但是我不能立即告诉您如何做到这一点。
Thanks to @Deokhwan Kim for the suggestion to limit search to ".el" files only. 感谢@Deokhwan Kim提出的将搜索限制为仅“ .el”文件的建议。
Mx find-library
RET prompts you for the name of a library, and then visits that file. Mx
find-library
RET提示您输入find-library
的名称,然后访问该文件。
Calling it with point on a valid library name will make that the default prompt value. 用有效库名上的point调用它将成为默认提示值。
Calling it with point anywhere within a require
statement will also do the right thing. 用
require
语句中的任意点调用它也会做正确的事情。
I use find-library
frequently, and bind it to Ch Cl for convenience. 我经常使用
find-library
,并将其绑定到Ch Cl以方便使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.