5

I'm using the new emacs 24.4 prettify-symbols-mode, but it isn't behaving consistently.

I turn it on with:

(prettify-symbols-mode t)
(global-prettify-symbols-mode t)

And I'm trying to change the way python source code looks with the follownig setup:

(add-hook 'python-mode-hook
          (lambda ()
            (push '("**2" . ?²) prettify-symbols-alist)
            (push '("_x" . ?ᵪ) prettify-symbols-alist)
            (push '("sum" . ?∑) prettify-symbols-alist)))

This works, but not consistently. For example,

x**2 x_x and sum(x) all look good.

The inconsistent part is that x**23 maintains the superscript 2, but the 3 is regular. But if I say x**2+2, or x**2, then the **2 is not pretty (and it should be). I'd like the 2 to only be superscript when it is followed by certain characters (space, plus, comma, etc.). Alternatively, not superscript if followed by [0-9].

Meanwhile, sum behaves correctly. sum(, sum**2, sum+, and others are pretty (as they should be) and summer is not (correctly).

  • The documentation for prettify-symbols-alist says: Each element looks like (SYMBOL . CHARACTER), where the symbol matching SYMBOL (a string, not a regexp) will be shown as CHARACTER instead., so you won't be able to use regular expressions. – rekado Nov 21 '14 at 10:36
  • 1
    Please use M-x report-emacs-bug to report this problem, which will probably require extending prettify-symbols-mode. – Stefan Nov 21 '14 at 14:17
3

According to the documentation for prettify-symbols-alist, you cannot use regular expressions here:

Each element looks like (SYMBOL . CHARACTER), where the symbol matching SYMBOL (a string, not a regexp) will be shown as CHARACTER instead.

pretty-symbols-mode uses regexp-opt internally, which creates a big regular expression from all the strings in the car position of each of the alist pairs. If you really want regular expressions, you are probably better off defining font-lock keywords yourself, outside of the confines of prettify-symbols-mode.

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.