Insert a path into the current buffer
Sometimes I need to insert into a buffer a path (e.g. /home/user/.emacs) and I want to use emacs’ excellent completion capabilities. It turns out to be pretty easy to implement this function in elisp. Here is the snippet:
(defun insert-path () "Inserts a path into the buffer with completion" (interactive) (insert (expand-file-name (read-file-name "Path: "))))
As always, any comments on the code above are more than welcome
Another way of doing it suggested by Peter Mielke is:
(defun insert-path (file) "insert file" (interactive "FPath: ") (insert (expand-file-name file)))
I think this is a better option because uses interactive built-in support for file input rather than using the read-file-name function. Thank you for the tip Peter
Comments are currently closed.