In source code, I'd like to display “-” as “−”. In the font I use, the dash is very short and doesn't match the “+” at all. This is only to improve visual appearance. The character in the file must remain the same because it is code, which need to stay correct.
So far, I've used:
(add-hook 'python-mode-hook (lambda () (font-lock-add-keywords nil '(("\\B-\\B" (0 (progn (compose-region (match-beginning 0) (match-end 0) "−" 'decompose-region) nil))))) ))
\B-\B magic is so that this does not apply in text, i.e. within strings or comments, because I need it still displayed as a dash there.
Unfortunately, this cause a lot of false negatives.
Is there a way to automatically display one character as another outside strings and comments?