Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Emacs prettify-symbols-mode work on non-whitespace separated words.

Tags:

emacs

elisp

The new prettify-symbols-mode in Emacs works beautifully for translating:

lambda something -> λ something

I'd also like to make:

lambda.something -> λsomething

Sadly, prettify-symbols-mode only recognizes spaces as word/symbol separators by default.

Any ideas on how to use '.' as a token separator?

like image 833
Jarpy Avatar asked Oct 01 '22 11:10

Jarpy


1 Answers

The code that does the actual substitution is prettify-symbols--compose-symbol in prog-mode.el. It excludes matches if the character before or after the word has the character type word or symbol. In many mode, for example emacs-lisp-mode the . character has symbol type.

You could either change the syntax code for . in the major mode, you could tell font-lock to use a different character code when highlighting (see the variable font-lock-defaults for details), or you could do ju-jutsu on the prettify-symbols--compose-symbol mode like modifying it using defadvice or simply replace it with your own.

like image 155
Lindydancer Avatar answered Oct 02 '22 23:10

Lindydancer