The documentation of ivy-read
states that if the collection supplied is an alist, the selected candidate is passed as a cons cell to the function supplied in the :action
argument.
So why does the code snippet below return "C1"
or "C2"
, depending on the selection, and not (1 2 3)
or (3 4 5)
, respectively?
(ivy-read "Choose: "
(list (cons "C1" (list 1 2 3)) (cons "C2" (list 3 4 5)))
:action (lambda (x) (cdr x)))
I can work around this by doing something like the following, but I don't understand why I have to.
(let (tmp)
(ivy-read "Choose: "
(list (cons "C1" (list 1 2 3)) (cons "C2" (list 3 4 5)))
:action (lambda (x) (setq tmp (cdr x))))
tmp)