minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
584 stars 20 forks source link

Add cape-bbdb for completing name and email from BBDB #50

Closed ashton314 closed 2 years ago

ashton314 commented 2 years ago

This PR adds a new capf taking inspiration from the company-bbdb backend and written in the style of the cape-dict capf.

I use mu4e, and I've had great success combining this capf with the built-in capf provided by mu4e:

(add-to-list 'completion-at-point-functions (cape-super-capf #'cape-bbdb #'mu4e~compose-complete-contact))

Happy to hear any feedback on this capf.

minad commented 2 years ago

I have the feeling that this is out of scope of cape. Doesn't ebdb provide a capf? Why doesn't mu4e already include this? What about other mail clients? Not much, gnus, ...? Could you please summarize the situation? Is the company backend widely used? I am a bit out of my depth here since I don't use email in emacs (yet?). Cape is a gap filler package but most of the provided functions seem more general and basic than a bbdb specific capf.

minad commented 2 years ago

I don't have Emacs in front of me currently, so I cannot check, but as far as I understood bbdb.el is an external package distributed via ELPA? In this case the capf is out of scope here. It should be added instead to bbdb directly or if that is not possible you could create a bbdb-capf package. But I strongly suggest contributing to bbdb itself. Or consider using ebdb if this is the successor.

ashton314 commented 2 years ago

I don't use email in emacs (yet?).

You DON'T?! ;-)

bbdb.el is an external package distributed via ELPA? In this case the capf is out of scope here.

I see I misunderstood the scope of cape. This makes complete sense.

consider using ebdb if this is the successor

I did not know about ebdb—I can already see that it is way better documented than bbdb. (It'd be hard for anything to be less-documented than bbdb.) I've now got the behavior I want with this:

(use-package ebdb
  :config
  :hook
  ((mu4e-compose-mode) .
   (lambda ()
     (ebdb-records)                     ; populate capf cache
     (add-to-list 'completion-at-point-functions
                 (cape-super-capf #'ebdb-mail-dwim-completion-at-point-function
                                  #'mu4e~compose-complete-contact)))))

Still a little janky (I have to manually populate that cache) but it does what I want.

Background: mu4e does have a capf built-in, and it's wonderful. However, if you just have an email address without the attached name, you can't search by that person's name. There's no way to manually update the database; it's generated from reading your mail files. I'm pretty sure mu does this all up-front, so it's plenty fast, but a little inflexible. I wanted to have some contact book records show up first and then the autocomplete from previous correspondence.

Thanks for pointing me in the right direction, and thanks for such a solid package ecosystem!