gpt4 book ai didi

emacs - 使用 ido 插入文件名

转载 作者:行者123 更新时间:2023-12-04 02:55:31 24 4
gpt4 key购买 nike

我的 .emacs 中有下面的函数,我经常使用它来将本地文件的文件名/路径放入当前缓冲区。它运行良好,但是,我希望它能够完成 ido。但我似乎无法做到这一点......也许你可以帮助我。

(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)))))

最佳答案

打开 ido-everywhere 后,(interactive "f") 通常会使用 ido-read-file-name,它不仅会为您的功能提供自动补全,而且几乎无处不在。

如果你想只对这个函数有 ido 补全,而不是在任何地方,你可以在交互形式中显式调用 ido-read-file-name。在您的情况下使用 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)))))

关于emacs - 使用 ido 插入文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16764502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com