2013-10-19 55 views
1

是否可以獲取列表並將其保存在變量中? 我跑獲取由ido生成的候選人列表

(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準備了非常特殊的過濾器,我想直接使用結果。

+0

我們正在處理文件,或框架或。 。 。 ? – lawlist

+0

函數'ido-completion-read'獲得第二個參數中的任意列表。 – artscan

回答

1

變量`ido-matches'將包含上次調用ido-completion-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") 
+0

我可以讓它變得「無聲」,例如沒有與用戶交互? – artscan

+0

哦,我明白了。你想避免讓用戶按回車鍵。我必須考慮那個。 – justinhj

+0

暫時修改或創建一個類似的函數,用於改變'ido-read-internal'內的read-from-minibuffer代碼段和/或更改或創建不同類型的'ido-make-prompt'?我只是在旋轉車輪,大聲思考。 – lawlist

1
(defun eab/wrap-ido-completing-read() 
    (interactive) 
    (ido-completing-read prompt choices nil nil initial-input) 
    't) 

(defun ido-completing-read-silent (prompt choices initial-input) 
    (execute-kbd-macro (read-kbd-macro "M-: (eab/wrap-ido-completing-read) RET RET")) 
    ido-matches) 

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

我無意中發現的解決方案,它可以在其他情況下使用,對於不同的互動功能,如ido-completing-read

注意:eval-expression應綁定到M-:

相關問題