打开文件加强版
tags: file
在 Emacs 中, find-file(C-x C-f) 是用来打开文件的最基本方式,但有时当前 buffer 内有需要打开文件的信息,比如有如下文本:
/tmp/test.log
这时可以用 find-file-at-point 直接打开该文件。此外在编辑 elisp 配置时,有时候需要打开一个变量所代表的文件,我之前一直采用在 minibuffer 中执行命令的方式来打开,比如:
1(find-file custom-file)有些低效,能不能把 find-file-at-point 增强下,支持这种变量形式呢?当然是可以的:
1(defun my/find-file-at-point ()
2 "Enhanced version of `find-file-at-point'.
3First attempt to open file specified by `symbol-at-point', and fallback to normal one."
4 (interactive)
5 (condition-case nil
6 (thread-last (thing-at-point 'symbol t)
7 (intern)
8 (symbol-value)
9 (find-file-noselect)
10 (switch-to-buffer))
11 (t (call-interactively 'find-file-at-point))))最后,把上面这个命令绑定到常用的快捷键,比如 C-x C-f ,这样以后就可以方便的使用了。
收听方式

反馈
- 对节目有想法或发现内容错误?欢迎来信交流️