diff options
author | mousebot <mousebot@riseup.net> | 2021-08-10 00:08:18 +0200 |
---|---|---|
committer | mousebot <mousebot@riseup.net> | 2021-08-10 00:08:18 +0200 |
commit | 27edcd6b2010d4b2e39fe57ce6a5f26ef321d49e (patch) | |
tree | d528f698f9228907be8f33e6eda1c27f5f9eb962 /lisp | |
parent | d91d881a634f84e50c70e8be882bcfb278c64823 (diff) |
provide poll option descriptions in completing-read
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-tl.el | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 107f7eb..bacbebf 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -703,29 +703,36 @@ it is `mastodon-tl--byline-boosted'" options "\n") "\n"))) -(defun mastodon-tl--poll-vote () - "If toot at point is poll, call `mastodon-tl--poll-vote-yes'." - (interactive) - ;; hack coz i don't know how to put this if test before my interactive - (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) - (message "No poll here.") - (call-interactively 'mastodon-tl--poll-vote-yes))) - -(defun mastodon-tl--poll-vote-yes (option) - "Prompt user for OPTION to vote on poll at point." +(defun mastodon-tl--poll-vote (option) + "If there is a poll at point, prompt user for OPTION to vote on it." (interactive (list (let* ((toot (mastodon-tl--property 'toot-json)) (poll (mastodon-tl--field 'poll toot)) (options (mastodon-tl--field 'options poll)) + (options-titles (mapcar (lambda (x) + (cdr (assoc 'title x))) + options)) (options-number-seq (number-sequence 1 (length options))) (options-numbers (mapcar (lambda(x) (number-to-string x)) - options-number-seq))) - (completing-read "Poll option to vote for: " - options-numbers - nil ;predicate - t)))) ;require match + options-number-seq)) + (options-alist (mapcar* 'cons options-numbers options-titles)) + ;; we display both option number and the option title + ;; but also store option number as cdr, as we need it alone below + (candidates (mapcar (lambda (cell) + (cons (format "%s | %s" (car cell) (cdr cell)) + (car cell))) + options-alist))) + (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) + (message "No poll here.") + ;; var "option" = just the cdr, just the option number + (cdr (assoc + (completing-read "Poll option to vote for: " + candidates + nil ;predicate + t) ;require match + candidates)))))) (if (null (mastodon-tl--field 'poll (mastodon-tl--property 'toot-json))) (message "No poll here.") (let* ((toot (mastodon-tl--property 'toot-json)) |