An open API service indexing awesome lists of open source software.

https://github.com/unhammer/gnavatar

Elisp gravatar/bbdb-image wrapper
https://github.com/unhammer/gnavatar

avatar bbdb emacs gravatar

Last synced: 8 months ago
JSON representation

Elisp gravatar/bbdb-image wrapper

Awesome Lists containing this project

README

          

#+TITLE: gnavatar

[[https://melpa.org/#/gnavatar][https://melpa.org/packages/gnavatar-badge.svg]]
[[https://stable.melpa.org/#/gnavatar][https://stable.melpa.org/packages/gnavatar-badge.svg]]

* For users who want to override gravatar

If you want to use this instead of plain Gravatar everywhere, you can
use:
#+begin_src emacs-lisp
(advice-add 'gravatar-retrieve :around #'gnavatar-override)
#+end_src

For e-mails that exist in Gravatar, you'll get a result from
Gravatar. If they aren't in Gravatar, it'll try BBDB, using the
=image-uri= xfield.

Customize =gnavatar-providers= to change the priority (if you want to
try BBDB first).

* Use as library to insert avatars

The API is exactly the same as gravatar.el:

#+begin_src emacs-lisp
(require 'gnavatar)
(let ((buf (current-buffer)))
(gnavatar-retrieve
"a-gravatar-user@example.org"
(lambda (i)
(with-current-buffer buf
(insert-image i)))))
#+end_src

If you use it like this, your end-users don't have to add any advice.

* Interactive helpers to add images to BBDB

#+begin_src emacs-lisp
(require 'gnavatar-bbdb)
(define-key bbdb-mode-map (kbd "y") #'gnavatar-bbdb-add-clipboard-image-contents)
(define-key bbdb-mode-map (kbd "U") #'gnavatar-bbdb-add-clipboard-image-url)
#+end_src

Now you can copy an image and hit =y= or an image url and hit =U= on
a BBDB entry and it'll fill the image-uri field with that.

If you want to show the images in BBDB:
#+begin_src emacs-lisp
(defun my-bbdb-image-size-ok (image)
"Is IMAGE small enough?"
(let* ((size (image-size image))
(w (car size))
(h (cdr size)))
(and (< w 10) (< h 10))))

(defun my-bbdb-maybe-insert-image (record)
"If RECORD has an image that's small enough, insert it."
(when-let ((image (gnavatar-bbdb-create-image record)))
(when (my-bbdb-image-size-ok image)
(insert " ")
(insert-image image))))

(advice-add #'bbdb-display-name-organization :after #'my-bbdb-maybe-insert-image)
#+end_src