5

My .emacs file contains multiple file names as,

(load "~/.emacs.d/others/keymaps.el")
(load "~/.emacs.d/others/py.el")
(load "~/.emacs.d/others/web.el")

Is there a way any library, gives way for me to keep the cursor in the middle of file path and jump straight to the file content on pressing a shortcut.

(load "~/.emacs.d/others!!(cursor here)/py.el")

When the line cursor is in the middle of a file path, it must switch buffer to ~/.emacs.d/others/py.el

Drew
  • 75,699
  • 9
  • 109
  • 225
Madhavan
  • 1,957
  • 12
  • 28
  • I learned `(global-set-key [double-mouse-1] 'ffap)` here http://emacs.stackexchange.com/a/6088/. Instead of `double-mouse-1` you can use your favorite shortcut. If this helps you, be sure to upvote the answer provided in that link. – Name Jul 29 '15 at 12:07

3 Answers3

6

For ido users

Add the below to your config and then C-x C-f (which should be executing ido-find-file automatically with ido-mode enabled) on such file paths will open those files directly.

(setq ido-use-filename-at-point 'guess)

For ivy/counsel users

Add the below to your config and then M-x counsel-find-file (which you can conveniently bind to C-x C-f) on such file paths will open those files directly.

(setq counsel-find-file-at-point t)  
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
  • 1
    Pressing `M-n` also works for ido, ivy, and the default completion, even without the find-at-point customization. – abo-abo Jul 29 '15 at 13:49
3

Try this:

(defun visit-file-at-point ()
  "Visit file at point if it exists."
  (interactive)
  (let ((file (ffap-guess-file-name-at-point)))
    (when file
      (find-file file))))

If you don't mind one additional key-stoke, you can use built-in find-file-at-point command too.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
Mark Karpov
  • 4,893
  • 1
  • 24
  • 53
1

If you use Icicles then M-. always yanks the thing at point into the minibuffer.

This is just one use case of that, where you yank the file name at point.

One key to remember (or not -- M-? provides help).

Drew
  • 75,699
  • 9
  • 109
  • 225