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.

Eleno
  • 1,448
  • 11
  • 17
  • 1
    You can do some such things using code like that in some of the stuff linked from Pretty Symbol. – Drew Mar 31 '20 at 19:59
  • prettify-symbols-mode comes close, but it can replace matches with just one character, it seems. – Eleno Mar 31 '20 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 '20 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 01 '20 at 08: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 01 '20 at 11:43
  • @Drew Prettify Symbols Mode seems the only available solution. Please provide your suggestion as an answer, otherwise I will have to write an answer myself. Thanks. – Eleno Apr 03 '20 at 10:31
  • @elena: Please write up an answer, incorporating Lindydancer's mention that the replacement need not be a single character. Thx. (And you can accept your own answer.) – Drew Apr 03 '20 at 15:31

1 Answers1

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.
Eleno
  • 1,448
  • 11
  • 17