Hung-Yi's LogoHung-Yi’s Journal

How to Emojify Selectrum Candidates

Because who wouldn't want cute emojis in their Emacs completion candidates? Learn how to make the emacs-emojify and selectrum packages cooperate nicely.

If you use both emacs-emojify and selectrum and you’re having trouble getting emoji to show up properly in the list of completion candidates, especially after the latest round of selectrum updates (commit 21cee86) then I have an elisp configuration snippet that may help you.

Note that this configuration is written for the Doom Emacs distribution. If you’re using vanilla Emacs, you may need to replace the calls to use-package! and after! with their vanilla counterparts.

(use-package! emojify
  :commands (emojify-mode)
  :config
  (after! selectrum
    (advice-add #'selectrum--format-candidate
                :around
                (defun my/emojify-selectrum-candidate (orig-fun &rest args)
                  (emojify-string (apply orig-fun args))))))

Explanation

Since the new version of selectrum builds the candidate list as a string directly in memory, then displayed using an overlay – without a buffer to contain the list of candidates – emojify won’t work automatically because it works on buffer contents only.

However, there’s actually a utility function in emacs-emojify that allows direct emojification of a string input: emojify-string. As long as we advice-add this function around the output string of selectrum--format-candidate to emojify it, when selectrum uses those candidate strings to build the overlay, it picks up the emojified text properties.

Voilà 🎉!