2

I would light to highlight where prettify-symbols-mode has prettified a symbol. For example, if Emacs displays lambda as λ it could be displayed with a gray background, but if a literal λ occurs in the text, the background would remain white.

How can I achieve this?

1

You could add another matcher using the same regexp as prettify-symbols-mode, i.e. something like this:

(font-lock-add-keywords
 nil
 `((,(regexp-opt (mapcar 'car prettify-symbols-alist) t)
    (0 (when (funcall prettify-symbols-compose-predicate
                      (match-beginning 0)
                      (match-end 0)
                      (match-string 0))
         '(:background "grey80"))
       append)))
 'append)
| improve this answer | |
  • This works, but when prettify-symbols-unprettify-at-point is t this also highlights the replaced string when cursor is at the prettified symbol. Is that a way to hightlight only the prettified symbol but not its original string? The reason is that I'm trying to use a face with a different font that has a symbol for the prettified symbol, but not for the original replaced characters. – darcamo Jun 26 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.