12

我是 . 的忠实粉丝ido-mode,以至于我想将它用于诸如describe-function或之类的事情find-tag,而不必编写类似“我可以在 Emacs 中搜索标签的 ido-mode 样式完成吗?”中的内容。每一个人。

两个都

(defalias completing-read ido-completing-read)

(setf 'completing-read 'ido-completing-read)

不起作用,至少部分是因为ido-completing-read调用completing-read了它的主体,所以任何简单的重新定义都会导致无限递归。

从理论上讲,它应该是可能的,因为文档字符串的第一行ido-completing-read是“内置的 Ido 替换completing-read”。我环顾四周,似乎找不到其他尝试或成功的人。

我意识到Icicles可能提供了类似的东西,我可能最终还是会使用它,但这比我现在想采取的更冒险。

谢谢你的帮助。

4

6 回答 6

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

哦,对于使用 ido in M-x,请使用amx

于 2009-06-19T18:58:29.650 回答
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))))

这适用于除 subr 之外的所有内容,其中执行扩展命令是最重要的(绑定到 Mx 的内容)。但是我们可以从 Mx 中得到我们想要的

(global-set-key
 "\M-x"
 (lambda ()
   (interactive)
   (call-interactively
    (intern
     (ido-completing-read
      "M-x "
      (all-completions "" obarray 'commandp))))))
于 2009-07-05T20:04:41.693 回答
3

我认为还没有ido-mode为此做好准备。特别是,ido-completing-read目前仅适用于字符串,同时也completing-read支持 alists。一旦您想要对要完成的项目有不同的用户级描述,这一点非常重要。

因此,我对它还不能开箱即用并不感到惊讶。如果不自己修改代码,最好的选择可能是提交错误报告/功能请求。

于 2009-05-26T15:48:52.023 回答
1

Using Emacs 24.3, ido-ubiquitous didn't work for me. So tried this and it is working fine so far:

(defun my-completing-read (prompt collection &optional predicate
                  require-match initial-input
                  hist def inherit-input-method)
  (if (listp collection)
      (ido-completing-read prompt collection predicate require-match
               initial-input hist def inherit-input-method)
    (completing-read-default prompt collection predicate require-match
                 initial-input hist def inherit-input-method)))

(setq completing-read-function 'my-completing-read)
于 2013-03-12T13:43:18.193 回答
1

Ido 带有一个应该执行此操作的函数,因此只需在您的 .emacs 文件中调用它:

(ido-无处不在 t)

于 2009-05-25T15:01:56.577 回答
0

只是一个想法:您是否尝试过编辑ido-completing-readcalloriginal-completing-read而不是completing-read,定义original-completing-read为当前completing-read,然后执行您的 defalias 或 setf 事情?

于 2009-05-25T09:03:46.363 回答