I'm using prettify-symbol mode together with Pragmata Pro.el. Ligatures work perfectly fine in the source code but for some reason with comments they don't. I think I'm missing something since it's not the first time I've fought with ligatures in Emacs.


When symbols are composed with prettify-symbols-mode is controlled by prettify-symbols-compose-predicate. By default this will only compose symbols if they are at a word boundary and not inside a comment or string. It checks the parser state with syntax-ppss to verify that the point is outside of a comment or string. We can change this to only check if we outside a string. That way it will compose symbols in comments as well.

The only part of this function we changed was to change (nth 8 (syntax-ppss)) (which means in comment or string) to (nth 3 (syntax-ppss)) (which means in string).

  (setq prettify-symbols-compose-predicate
        (defun my-prettify-symbols-default-compose-p (start end _match)
          "Same as `prettify-symbols-default-compose-p', except compose symbols in comments as well."
          (let* ((syntaxes-beg (if (memq (char-syntax (char-after start)) '(?w ?_))
                                   '(?w ?_) '(?. ?\\)))
                 (syntaxes-end (if (memq (char-syntax (char-before end)) '(?w ?_))
                                   '(?w ?_) '(?. ?\\))))
            (not (or (memq (char-syntax (or (char-before start) ?\s)) syntaxes-beg)
                     (memq (char-syntax (or (char-after end) ?\s)) syntaxes-end)
                     (nth 3 (syntax-ppss)))))))
  • Thank you very much! Works like a charm <3 – FieryCod Feb 8 at 22:41
  • It seems that indeed for emacs-lisp it works like a charm, but for other modes like clojure-mode it does not. Maybe you know why? – FieryCod Feb 9 at 8:57
  • Maybe prettify-symbols-compose-predicate is buffer local. Can you check the value of it inside closure-mode and make sure that is it is pointing to our function? – Prgrm.celeritas Feb 9 at 13:48
  • Thank you one more time :D I just defined the function globally and now everything works as expected! – FieryCod Feb 9 at 14:04

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.