4

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

  • I learned (global-set-key [double-mouse-1] 'ffap) here 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

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.

| improve this answer | |
5

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)  
| improve this answer | |
  • 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
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).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.