Created
August 15, 2014 17:23
-
-
Save DarwinAwardWinner/174abce98ff799d1daa0 to your computer and use it in GitHub Desktop.
An implementation of "completing-read-multiple" by using "completing-read" in a loop. This allows it to use "completing-read-function" for multiple completion as well. For example, if you have "ido-ubiquitous-mode" enabled, you get multiple completion via ido.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun my-crm-custom (prompt table &optional predicate require-match initial-input hist def inherit-input-method) | |
| (loop with return-list = nil | |
| with next-value = nil | |
| with def-list = (s-split crm-separator (or def "")) | |
| with def-list-no-empty-string = (remove "" def-list) | |
| with def-text = (when def-list-no-empty-string | |
| (concat "(" (s-join crm-separator def-list) ")")) | |
| ;; Need to clear this | |
| with def = nil | |
| ;; Save original prompt and construct prompt with defaults | |
| with orig-prompt = prompt | |
| with prompt = (concat orig-prompt def-text) | |
| ;; Enable entry of empty string with ido | |
| with ido-ubiquitous-enable-old-style-default = t | |
| ;; Pre-expand completions table | |
| with table = (delete-dups | |
| (nconc def-list-no-empty-string | |
| (all-completions "" table predicate))) | |
| with predicate = nil | |
| do (message "Table: %S" table) | |
| do (setq next-value | |
| (completing-read prompt | |
| table | |
| predicate | |
| require-match | |
| initial-input | |
| hist | |
| nil ; Default is handled elsewhere | |
| inherit-input-method)) | |
| ;; Fold empty string to nil | |
| if (string= next-value "") | |
| do (setq next-value nil) | |
| ;; Empty input on first prompt returns result | |
| if (null next-value) | |
| return (or return-list def-list) | |
| else | |
| collect next-value into return-list | |
| and do (message "Read next value: %S" next-value) | |
| ;; Remove selected item from stuff, and unset initial things | |
| and do (setq | |
| prompt (concat orig-prompt "(" | |
| (s-join crm-separator return-list) crm-separator) | |
| table (delete next-value table) | |
| initial-input nil))) | |
| ;; Test it out | |
| (my-crm-custom "Select several: " '("A" "B" "C" "D" "E") nil t nil nil "D,E,A") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment