【问题标题】:Get the list of candidates generated by ido获取 ido 生成的候选列表
【发布时间】:2013-10-19 01:06:27
【问题描述】:

是否可以获取列表并将其保存在变量中? 我跑

(ido-completing-read "prompt: " '("one" "two" "three" "four" "five") nil nil "t")

然后 ido 生成候选人列表{two | three}。我想要这样的东西

(setq my-desired-list (ido-completing-read-silent '("one" "two" "three" "four" "five") nil nil "t"))

my-desired-list执行后的值为("two" "three")。 我对 ido 使用了复杂的设置,它为 choices 准备了非常特殊的过滤器,我想直接使用结果。

【问题讨论】:

  • 我们是在处理文件、帧还是 . . . ?
  • 函数ido-completing-read 在第二个参数中获取任意列表。

标签: emacs elisp ido


【解决方案1】:

变量 `ido-matches' 将包含上次调用 ido-completing-read 的匹配项。所以这就是你想要的:

(defun ido-completing-read-silent (prompt choices initial-input)
  (ido-completing-read prompt choices nil nil initial-input)
  ido-matches)

(ido-completing-read-silent "prompt: " '("one" "two" "three" "four" "five") "t")
;; ("two" "three")

【讨论】:

  • 我可以让它真正“静音”,例如不与用户互动?
  • 哦,我明白了。您希望避免让用户按下回车键。我得考虑一下。
  • 临时修改或创建类似的函数,以更改read-from-minibuffer 内的read-from-minibuffer 代码部分和/或更改或创建不同类型的ido-make-prompt?我只是在转动我的轮子并大声思考。
  • @lawlist 感谢您的讨论,请参阅我的回答。我认为它很有用,需要泛化。
【解决方案2】:
(defun ido-completing-read-silent (prompt choices initial-input)
  (run-with-timer 0.0001 nil 'exit-minibuffer)
  (ido-completing-read prompt choices nil nil initial-input)
  (mapcar (lambda (x) (flx-propertize x nil)) ido-matches))

(equal (ido-completing-read-silent "prompt: " '("one" "two" "three" "four" "five") "t")
       '("three" "two"))

该解决方案可用于其他情况,用于不同的交互功能,例如ido-completing-read

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 2018-11-23
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多