[英]insert filename using ido
I have the function below in my .emacs
which I use quite frequently to put the filename/path of a local file in the current buffer. 我在
.emacs
有以下函数,我经常使用它将本地文件的文件名/路径放在当前缓冲区中。 It is working nicely, however, I'd like it to have ido
completion. 它工作得很好,但是,我希望它有完成
ido
。 But I seem unable to achieve that... maybe you can help me. 但我似乎无法实现这一点......也许你可以帮助我。
(defun insert-file-name (filename &optional args)
"Insert name of file FILENAME into buffer after point.
Prefixed with \\[universal-argument], expand the file name to
its fully canocalized path. See `expand-file-name'.
Prefixed with \\[negative-argument], use relative path to file
name from current directory, `default-directory'. See
`file-relative-name'.
The default with no prefix is to insert the file name exactly as
it appears in the minibuffer prompt."
;; Based on insert-file in Emacs -- ashawley 20080926
(interactive "*fInsert file name: \nP")
(cond ((eq '- args)
(insert (expand-file-name filename)))
((not (null args))
(insert (filename)))
(t
(insert (file-relative-name filename)))))
With ido-everywhere
turned-on, (interactive "f")
will normally use ido-read-file-name
, which will not only provide automatic completion for your function, but also almost everywhere. 随着
ido-everywhere
打开, (interactive "f")
通常会使用ido-read-file-name
,这不仅会为您的功能提供自动完成功能,而且几乎无处不在。
If you want to have ido completion only for this function, but not everywhere, you can explicitly call ido-read-file-name
in the interactive form. 如果你想只为这个函数完成ido,而不是到处都是,你可以在交互式表单中显式调用
ido-read-file-name
。 One side effect of using ido in your case is that it seems to always return a full path, making the distinction between filename
and (expand-file-name filename)
effectless. 在你的情况下使用ido的一个副作用是它似乎总是返回一个完整的路径,使
filename
和(expand-file-name filename)
之间的区别无效。
(defun insert-file-name (filename &optional args)
"Insert name of file FILENAME into buffer after point.
Prefixed with \\[universal-argument], expand the file name to
its fully canocalized path. See `expand-file-name'.
Prefixed with \\[negative-argument], use relative path to file
name from current directory, `default-directory'. See
`file-relative-name'.
The default with no prefix is to insert the file name exactly as
it appears in the minibuffer prompt."
;; Based on insert-file in Emacs -- ashawley 20080926
(interactive `(,(ido-read-file-name "File Name: ")
,current-prefix-arg))
(cond ((eq '- args)
(insert (expand-file-name filename)))
((not (null args))
(insert filename))
(t
(insert (file-relative-name filename)))))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.