Hi,
Is there a substitute in emacs for the vi "gf" command? meaning try to open the file which is under the cursor right now if a real file name is in fact there.
Thanks
-
You want the
find-file-at-pointfunction (which is also aliased toffap). It's not bound to a key by default, but you can useM-x ffapOr, you can put in your
.emacsfile:(ffap-bindings)This will replace many of the normal
find-filekey bindings (likeC-x C-f) withffap-based versions. See the commentary inffap.elfor details. -
Thanks, it works quite well but somehow the vi (gf) version is still somewhat smarter. I think it looks at some path variable for search paths.
I made something which is needlessly complicated but works for me (only in linux). It uses the "locate" command to search for the path under the cursor. I guess it could be made smarter by searching the relative path to the current file first. sorry for my bad elisp skills...It can probably be achieved in a much nicer way.
put in your .emacs, then use with M-x goto-file
(defun shell-command-to-string (command) "Execute shell command COMMAND and return its output as a string." (with-output-to-string (with-current-buffer standard-output (call-process shell-file-name nil t nil shell-command-switch command)))) (defun goto-file () "open file under cursor" (interactive) (find-file (shell-command-to-string (concat "locate " (current-word) "|head -c -1" )) ))cjm : My Emacs already has shell-command-to-string defined in simple.el
0 comments:
Post a Comment