Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mgalgs
Created October 31, 2011 22:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgalgs/1329188 to your computer and use it in GitHub Desktop.
Save mgalgs/1329188 to your computer and use it in GitHub Desktop.
(defun ido-completing-read-multiple (prompt choices &optional predicate require-match initial-input hist def sentinel)
"Read multiple items with ido-completing-read. Reading stops
when the user enters SENTINEL. By default, SENTINEL is
\"_done_\". SENTINEL is disambiguated with clashing completions
by appending _ to SENTINEL until it becomes unique. So if there
are multiple values that look like SENTINEL, the one with the
most _ at the end is the actual sentinel value. See
documentation for `ido-completing-read' for details on the
other parameters."
(let
((sentinel (if sentinel sentinel ".done_"))
(done-reading nil)
(res ()))
;; uniquify the SENTINEL value
(while (find sentinel choices)
(setq sentinel (concat sentinel "_")))
(setq choices (cons sentinel choices))
;; read some choices
(while (not done-reading)
(setq this-choice (ido-completing-read prompt choices predicate require-match initial-input hist def))
(if (equal this-choice sentinel)
(setq done-reading t)
(setq res (cons this-choice res))))
;; return the result
res
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment