我是一个大风扇ido-mode
,以至于我想用它喜欢的东西describe-function
或find-tag
等等,而无需编写像在"我能得到IDO模式完成了在Emacs搜索标签?" 每一个人.
都
(defalias completing-read ido-completing-read)
和
(setf 'completing-read 'ido-completing-read)
不起作用,至少部分是因为它的主体ido-completing-read
调用completing-read
,所以任何简单的重新定义都会导致无限递归.
从理论上讲,它应该是可能的,因为文档字符串的第一行ido-completing-read
是"Ido替换内置函数" completing-read
.我环顾四周,似乎找不到任何试图或成功的人.
我意识到Icicles可能会提供类似这样的东西,无论如何我最终可能会继续这样做,但这比我现在想要的更多一点.
谢谢你的帮助.
编辑:现在是MELPA提供的Emacs 软件包.它已经扩展为一个成熟的次要模式.开发发生在GitHub上.
以下是Jacobo答案的改进.归功于原始魔法.我添加了一个覆盖变量,您可以使用它来阻止ido-completing-read
在特定函数中使用.如果没有完成,我还添加了一个使用原始完成读取的检查(这偶尔发生,例如在org-remember-apply-template
org-mode中,这与Jacobo的原始建议打破).
(defvar ido-enable-replace-completing-read t "If t, use ido-completing-read instead of completing-read if possible. Set it to nil using let in around-advice for functions where the original completing-read is required. For example, if a function foo absolutely must use the original completing-read, define some advice like this: (defadvice foo (around original-completing-read-only activate) (let (ido-enable-replace-completing-read) ad-do-it))") ;; Replace completing-read wherever possible, unless directed otherwise (defadvice completing-read (around use-ido-when-possible activate) (if (or (not ido-enable-replace-completing-read) ; Manual override disable ido (boundp 'ido-cur-list)) ; Avoid infinite loop from ido calling this ad-do-it (let ((allcomp (all-completions "" collection predicate))) (if allcomp (setq ad-return-value (ido-completing-read prompt allcomp nil require-match initial-input hist def)) ad-do-it))))
哦,使用ido M-x,使用smex
Hocus pocus,abracadabra,presto!
(defadvice completing-read (around foo activate) (if (boundp 'ido-cur-list) ad-do-it (setq ad-return-value (ido-completing-read prompt (all-completions "" collection predicate) nil require-match initial-input hist def))))
这适用于除了subr之外的所有东西,execute-extended-command是重要的(绑定到Mx的东西).但我们可以从Mx获得我们想要的东西
(global-set-key "\M-x" (lambda () (interactive) (call-interactively (intern (ido-completing-read "M-x " (all-completions "" obarray 'commandp))))))