hax*_*ney 11 emacs elisp editing ido-mode icicles
我是一个大风扇ido-mode
,以至于我想用它喜欢的东西describe-function
或find-tag
等等,而无需编写像在"我能得到IDO模式完成了在Emacs搜索标签?" 每一个人.
都
(defalias completing-read ido-completing-read)
Run Code Online (Sandbox Code Playgroud)
和
(setf 'completing-read 'ido-completing-read)
Run Code Online (Sandbox Code Playgroud)
不起作用,至少部分是因为它的主体ido-completing-read
调用completing-read
,所以任何简单的重新定义都会导致无限递归.
从理论上讲,它应该是可能的,因为文档字符串的第一行ido-completing-read
是"Ido替换内置函数" completing-read
.我环顾四周,似乎找不到任何试图或成功的人.
我意识到Icicles可能会提供类似这样的东西,无论如何我最终可能会继续这样做,但这比我现在想要的更多一点.
谢谢你的帮助.
Rya*_*son 10
编辑:现在是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))))
Run Code Online (Sandbox Code Playgroud)
哦,使用ido M-x,使用smex
小智 7
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))))
Run Code Online (Sandbox Code Playgroud)
这适用于除了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))))))
Run Code Online (Sandbox Code Playgroud)
我认为ido-mode
还没有为此做好准备。特别是,ido-completing-read
目前仅适用于字符串,同时completing-read
也支持列表。当您想要对要完成的项目有不同的用户级别描述时,这一点非常重要。
因此,我对它还不能开箱即用并不感到惊讶。如果不亲自修改代码,您最好的选择可能就是提交错误报告/功能请求。