在Dired缓冲区中使用ido

5
我经常使用dired-mode,最近开始使用ido
(ido-mode 1); enable ido-mode
(setq ido-enable-flex-matching t); flexibly match names via fuzzy matching
(setq ido-everywhere t); use ido-mode everywhere, in buffers and for finding files
(setq ido-use-filename-at-point 'guess); for find-file-at-point
(setq ido-use-url-at-point t); look for URLs at point
(setq ffap-require-prefix t); get find-file-at-point with C-u C-x C-f 

当我在dired缓冲区中使用C复制文件时,我仍然需要使用“标准方式”来指定文件被复制到的新位置。也就是说,我必须使用标准的TAB自动完成,但是没有ido自动完成的选项。对于移动文件等操作,R同样也适用。因此,我想知道是否可能让ido在dired缓冲区中也能够支持CR操作?

2个回答

6
看起来我遇到了你正在经历的同样的问题。一些调查表明,我们需要覆盖变量read-file-name-function,默认情况下调用read-file-name-function-default。但是,查看ido-everywhere(这是一个小模式)的源代码,它已经为我们做到了这一点。
解决方案: 不要使用(setq ido-everywhere t),而是替换为:(ido-everywhere t)。 对我来说,这个修复方法有效,当您使用C或类似功能时,在dired缓冲区中调用ido-read-file-name
另一个选择: 您还可以考虑使用ido-ubiquitous的增强版本:https://github.com/DarwinAwardWinner/ido-ubiquitous
;;; Commentary:

;; You may have seen the `ido-everywhere' variable in ido.el and got
;; excited that you could use ido completion for everything. Then you
;; were probably disappointed when you realized that it only applied
;; to *file names* and nothing else. Well, ido-ubiquitous is here to
;; fulfill the original promise and let you use ido completion for
;; (almost) any command that uses `completing-read' to offer you a
;; choice of several alternatives.

有趣的是,C 复制可以工作,但 R 重命名和移动不能这样工作 :-( - Marius Hofert
从文档中可以看出,C是一个闭包,而R是一个函数。 - Nicolas Dudebout
1
他们肯定有很好的理由这样做,但我要说的是,执行(put 'dired-do-rename 'ido 'find-file)会产生一个ido-completing read,并且对我重命名基本文件和目录没有任何不良后果。虽然我不建议这样做 - 我会提交一个错误报告/功能请求。 - assem
@MariusHofert,我发现这个解决方法非常好用。Ido提供了C-f快捷键来手动编辑输入。我还使用了“(setq ido-show-dot-for-dired t) ;; put . as the first item”设置,也许这就是为什么它对我很有效的原因。 - sp3ctum
嘿,我认为我可以回答这个帖子中的一些问题。首先,ido-ubiquitous(我的软件包)仅设计用于基本使用completing-read,即不读取文件或目录,因此它对此处的任何内容都没有帮助。其次,我故意在dired-do-rename中禁用ido,不是因为它无法在那里工作,而是因为ido被优化用于完成现有文件名,而重命名的目的(通常)是创建一个新文件,而不是覆盖现有文件,因此ido并不真正针对重命名的用例进行优化。所以请放心在dired重命名时使用ido。 - Ryan C. Thompson
显示剩余6条评论

3
我发现使用 R 键的 (put 'dired-do-rename 'ido 'find-file) 可以很好地工作,如果你需要停留在一个路径上,你只需要按下 C-j 而不是完成文件名。

不幸的是,这对我来说没有任何改变。 - Marius Hofert
你能解释一下你想做什么以及它为什么不起作用吗?还有,为什么要踩我? - Silex
那篇帖子确实不太精确。我后来才发现(见下文)这个“解决方案”的影响/变化。可能是因为副作用,所以被踩了。这不是一个干净的问题解决方案,它会影响许多其他“好”的行为,因此应该小心使用。我应该直接说出来,而不是使用踩按钮。对此我很抱歉。 - Marius Hofert
对我来说运行良好。请看我的评论,关于assem的解决方案。 - sp3ctum
我使用ido-ubiquitous包,但这个解决方案是唯一适用于我的。如果您想为所有dired-do-函数启用此解决方案,请将以下内容放入您的初始化文件中:(eval-after-load 'dired '(progn (mapatoms (lambda (symbol) (if (s-starts-with? "dired-do-" (symbol-name symbol)) (put symbol 'ido 'find-file))))))。请注意,此解决方案需要s.el,但您真的应该安装该库。 - GDP2
更正我的上一条评论:在那里不需要s.el;请改用string-prefix-p。此外,在所有dired-do-函数上执行此解决方案实际上是一个坏主意,因为其中一些函数不适合使用Ido。这个解决方案更好,因为它只针对有意义的Ido函数:(eval-after-load dired '(progn (dolist (action '(dired-do-compress dired-do-compress-to dired-do-copy dired-do-hardlink dired-do-relsymlink dired-do-rename dired-do-symlink dired-do-touch epa-dired-do-decrypt epa-dired-do-encrypt do-sign epa-dired-do-verify)) (put action 'ido 'find-file)))) - GDP2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接