I know how to set coloring for an interactive R session in ESS + Emacs for all numbers. Is there a way to drill down further and set different colors for negative numbers?
1 Answer
highlight-numbers mode will provide color for all numbers in a buffer, and you can use it in your R process buffer. It only supports a single highlight, so you can't use a different color for positive and negative numbers. However, you can tweak it to highlight only negative numbers, leaving the other numbers to be colored according to ESS's font-locking.
The following code colors negative numbers red in an ESS R process buffer. There are a few edge cases where it doesn't apply, if that bothers you you may need to further refine the rx expression to more accurately catch everything you want. You do need to install highlight-numbers mode before this will work!
(add-hook 'inferior-ess-r-mode-hook 'highlight-numbers-mode)
(eval-after-load "highlight-numbers.el"
(progn (puthash 'inferior-ess-r-mode
(rx (and
not-wordchar
"-"
symbol-start
(+ digit)
(? (and "." (* digit)))
(? (and (any "eE")
(? (any "-+"))
(+ digit)))))
highlight-numbers-modelist)
(set-face-attribute 'highlight-numbers-number nil
:foreground "red" )))
highlight-numbers
may be relevant.