Skip to content

Instantly share code, notes, and snippets.

@mrwacky42
Created April 13, 2015 23:02
Show Gist options
  • Save mrwacky42/9d2aa9f3d4080b9676cc to your computer and use it in GitHub Desktop.
Save mrwacky42/9d2aa9f3d4080b9676cc to your computer and use it in GitHub Desktop.
(setq checkboxes '(("yesno" :options ("Yes" "No") :default "Yes")
("passfail" :options ("Pass" "Fail") :default "Pass")))
(defun create-checkboxes ()
(let ((choice-options (mapcar #'car checkboxes)))
(completing-read "Choices: " checkboxes nil t nil nil (first choice-options))))
(defun get-some-checkboxes ()
(let* ((choicekey (create-checkboxes))
(choicedefault (plist-get (cdr (assoc choicekey checkboxes)) :default))
(choiceoptions (plist-get (cdr (assoc choicekey checkboxes)) :options)))
(setq checked (completing-read "Which is checked?: " choiceoptions nil t nil nil choicedefault))
(mapconcat (function (lambda (x) (format "[%s] %s" (if (string= x checked) "✔" "") x)))
choiceoptions " ")))
(get-some-checkboxes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment