Original link: https://emacstalk.github.io/post/021/
In Emacs, find-file(Cx Cf)
is the most basic way to open a file, but sometimes there is information about the file that needs to be opened in the current buffer, such as the following text:
/tmp/test.log
Then you can use find-file-at-point
to open the file directly. In addition, when editing the elisp configuration, sometimes it is necessary to open the file represented by a variable. I have always used the method of executing commands in the minibuffer to open, such as:
(find-file custom-file)
Some inefficiencies, can you enhance find-file-at-point
to support this variable form? Of course it is possible:
(defun my/find-file-at-point () "Enhanced version of `find-file-at-point' . First attempt to open file specified by `symbol-at-point' , and fallback to normal one." (interactive) (condition-case nil (thread-last (variable-at-point) ( symbol-value ) (find-file-noselect) (switch-to-buffer)) ( t ( call-interactively 'find-file-at-point ))))
Finally, bind the above command to a common shortcut key, such as Cx Cf
, so that it can be used conveniently in the future.
This article is reprinted from: https://emacstalk.github.io/post/021/
This site is for inclusion only, and the copyright belongs to the original author.