Goto file in Emacs

Is there an emacs replacement for the vi "gf" command? that is, try to open the file under the cursor right now if the actual file name actually exists.

thank

+45
emacs
Nov 03 '08 at 17:27
source share
2 answers

You need the find-file-at-point function (which is also smoothed before ffap ). It is not tied to the default key, but you can use

 Mx ffap 

Or you can add the .emacs file:

 (ffap-bindings) 

This will replace many of the usual find-file key bindings (e.g. Cx Cf ) with ffap based ffap . See Comment in ffap.el for more ffap.el .

+66
Nov 03 '08 at 17:36
source share

Thanks, this works very well, but somehow the vi (gf) version is still a bit smarter. I think he is looking at a path variable for search paths.

I did something that is uselessly complicated, but works for me (only on Linux). It uses the locate command to find the path under the cursor. I think this can be done smarter by first looking at the relative path to the current file. sorry for my poor elisp skills ... This can probably be achieved much nicer.

enter your .emacs, then use goto-file with Mx

 (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" )) )) 
+5
Nov 04 '08 at 8:35
source share



All Articles