aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@disroot.org>2024-10-28 15:49:10 +0100
committermarty hiatt <martianhiatus@disroot.org>2024-10-28 20:20:31 +0100
commit5d3b80d6a85a036aabcf690bd07cef92b502c33d (patch)
tree0388f72393e2b151206ed2d43e2da8f5e3adb2b8
parent7bf9d25de2ae4b1157ae61badddbdee32a51575b (diff)
poll transient: add another option interactively
-rw-r--r--lisp/mastodon-transient.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el
index ceea384..68d8b24 100644
--- a/lisp/mastodon-transient.el
+++ b/lisp/mastodon-transient.el
@@ -233,6 +233,37 @@ the format fields.X.keyname."
(let ((instance (mastodon-instance-data)))
(mastodon-toot--fetch-max-poll-option-chars instance)))
+(transient-define-suffix mastodon-transient--choice-add ()
+ "docstring"
+ (interactive)
+ :transient 'transient--do-stay
+ (let* ((args (transient-args (oref transient-current-prefix command)))
+ (choice-count (length
+ (cl-member-if
+ (lambda (x)
+ (equal (car x) 'one))
+ args)))
+ (inc (1+ choice-count))
+ (next (number-to-string inc))
+ (next-symbol (pcase inc
+ (5 'five)
+ (6 'six)
+ (7 'seven)
+ (8 'eight)
+ (9 'nine))))
+ (if (or ;(>= choice-count (mastodon-transient-max-poll-opts))
+ (= choice-count 9))
+ ;; FIXME when we hit '10', we get a binding clash with '1'. :/
+ (message "Max choices reached")
+ (transient-append-suffix
+ 'mastodon-create-poll
+ '(2 -1)
+ `(,next "" ,next
+ :class mastodon-transient-poll-choice
+ :alist-key ,next-symbol
+ :transient t))))
+ (transient-setup 'mastodon-create-poll))
+
(transient-define-prefix mastodon-create-poll ()
"A transient for creating a poll."
;; FIXME: handle existing polls when editing a toot
@@ -260,6 +291,7 @@ the format fields.X.keyname."
["Update"
("C-c C-c" "Save and done" mastodon-create-poll-done)
("C-c C-k" "Delete all" mastodon-clear-poll)
+ ("C-c C-s" "Add another poll choice" mastodon-transient--choice-add)
("C-x C-k" :info "Revert all")]
(interactive)
(if (not mastodon-active-user)