开发者

Emacs in place filename / path insertion

开发者 https://www.devze.com 2023-02-13 10:31 出处:网络
I am looking for a way to insert a filename/path inline while editing.Something like an inline ido-style file selection would be perfect.Is there anything like th开发者_Python百科at out there?I always

I am looking for a way to insert a filename/path inline while editing. Something like an inline ido-style file selection would be perfect. Is there anything like th开发者_Python百科at out there?


I always use comint-dynamic-complete-filename for this. This does not seem to be loaded by default, but provided by comint-mode. Thus you could put something like

(autoload 'comint-dynamic-complete-filename "comint" nil t)
(global-set-key "\M-]" 'comint-dynamic-complete-filename)

in your ~/.emacs or the like. Use your own prefered keybinding of course.


Okay, if you want to just insert the current file name at point, then

 (insert (expand-file-name (buffer-file-name)))

should do it.

If you want to be able to find a file at any path, then you'll want to replicate some of the code in find-file-noselect in files.el at about line 1714 .

In either case, if you want to bind this a a function, you'll probably want

 (defun insert-file-name-at-point ()
    (interactive) .... )


(defun insert-file-name (file &optional relativep)
  "Read file name and insert it at point.
With a prefix argument, insert only the non-directory part."
  (interactive "fFile: \nP")
  (when relativep (setq file  (file-name-nondirectory file)))
  (insert file))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号