Hung-Yi’s Journal

Front-end Developer, Emacs Adventurer, Home Cook

01 Mar 2021

How to Emojify Selectrum Candidates

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. Read on to see it.

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à 🎉!