abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

Improving my Ivy code: do I need to write accumulators? #2688

Open WorldsEndless opened 4 years ago

WorldsEndless commented 4 years ago

I am writing an Ivy that goes through my bbdb and builds the "to" string on an email, allowing me to search users by group (organization) by including that as part of the string, but then chopping that off the string before inserting it. This functionality makes heavy use of multiple selections in Ivy; however, it looks like this normally executes the :action on each selection individually. In order to insert format properly, I need to operate on my selections as a collection, using string-join on them to make sure there is no comma following the last item. Then my :action is just to push the result to the accumulator, which will be processed later.

Is this idiomatic to use an accumulator list to collect multiple selections, or is there a built-in way I don't know about?

basil-conto commented 4 years ago

is there a built-in way I don't know about?

FWIW, BBDB has built-in support for completing organisations, and this is enabled by default via the user option bbdb-completion-list. Try entering part of an organisation's name and invoking M-x bbdb-complete-mail, for example.

Since at least as far back as Emacs 27.1, message-mode supports BBDB completion via the standard in-buffer completion interface (i.e. what Ivy hooks into), but you need to opt in by enabling the user option message-expand-name-standard-ui.

Unfortunately, AFAICT, message-mode does not currently support completing organisations using the standard UI, which should be reported as a bug via M-x report-emacs-bug (I'll do this at some point if no-one has or does beat me to it in the meantime).