Home » Questions » Computers [ Ask a new question ]

How do I complete file paths in emacs?

How do I complete file paths in emacs?

Say for instance I'm editing a config file and I want to type in a path. Is there a plugin for emacs that lets you complete a file path in that buffer? I've searched for this and there's like a bazillion completion plugins out there.

Asked by: Guest | Views: 230
Total answers/comments: 2
bert [Entry]

"Try Hippie Expand, which as one of it's possibilities has 'try-complete-file-name. You can change the order and list of expansion functions hippie expand will use to favor expanding the file name.

Or, you could even write a custom wrapper that would only do the file name expansion. Something like:

(global-set-key (kbd ""C-M-/"") 'my-expand-file-name-at-point)
(defun my-expand-file-name-at-point ()
""Use hippie-expand to expand the filename""
(interactive)
(let ((hippie-expand-try-functions-list '(try-complete-file-name-partially try-complete-file-name)))
(call-interactively 'hippie-expand)))"
bert [Entry]

"Up to version 25, the vanilla, out-of-the-box

M-x comint-dynamic-complete-filename

and

M-x comint-replace-by-expanded-filename

both worked outside of comint mode. Of course, you can use the minibuffer's dynamic expansion to use less keystrokes to get to them (e.g., M-x comint-dynamic-complete-filename or M-x comint-replace-by-expanded-filename). Or, if you will be doing this frequently, you can bind them to key sequences of your choice using global-set-key .

For version 26+, it seems to me that you need to make sure that comint mode is explicitly loaded --- adding a line

(require 'comint)

in your .emacs file should make this work again.

Caveat: Not all applicable comint functions can be used this way. comint-dynamic-list-filename-completions doesn't seem to work outside of its native mode."