1

font-lock-add-keywords lets users highlight keywords. Can you also specify an alternative text? For example, in C source code, besides using a special face, we may wish to visualize ! as not, && as and, etc.

  • 1
    You can do some such things using code like that in some of the stuff linked from Pretty Symbol. – Drew Mar 31 at 19:59
  • prettify-symbols-mode comes close, but it can replace matches with just one character, it seems. – Eleno Mar 31 at 21:37
  • Yeah, that's why I said some of the stuff. Unless someone has a simple solution you may need to create overlays with display-property, or some such. – Drew Mar 31 at 21:38
  • 1
    @Elena, I think you can use Prettiy Symbol Mode to replace something into more than one character. The documentation says "CHARACTER can be a character, or it can be a list or vector, in which case it will be used to compose the new symbol as per the third argument of compose-region." Well, compose-region accepts strings, so my guess is that you can use a string, if not something like (?a ?n ?d) might work. (If someone has more time than I do, feel tree to try this and post an answer.) – Lindydancer Apr 1 at 8:27
  • @Lindydancer I have tried with (?a ?n ?d), but the replacement works by compressing the characters in the same box. Thanks anyway. – Eleno Apr 1 at 11:43
0

As indicated by @Drew and @Lindydancer, Prettify Symbols Mode - available with vanilla Emacs - allows for sequences of characters to be displayed by a custom character sequence, by customizing the prettify-symbols-alist buffer-local variable. Examples:

(push '("&&" . "∧") prettify-symbols-alist) ; Single character replacement.

(push '("&&" . (?a ?n ?d)) prettify-symbols-alist) ; String replacement.
| improve this answer | |

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.