1

In rainbow-mode, is it possible to toggle colouring only "words" or only "hexadicimals"? I don't see a variable I could set.

1 Answer 1

1

The code is in the library rainbow-mode.el, particularly the functions rainbow-turn-on and rainbow-turn-off. You can make copies of these functions that include or omit the appropriate sets of commands to get the result you want.

A quick and dirty example:

(defun rainbow-turn-off-hexadecimal ()
  "Turn off hexadecimal colours in rainbow-mode."
  (interactive)
  (font-lock-remove-keywords
   nil
   `(,@rainbow-hexadecimal-colors-font-lock-keywords)))

(defun rainbow-turn-off-words ()
  "Turn off word colours in rainbow-mode."
  (interactive)
  (font-lock-remove-keywords
   nil
   `(,@rainbow-x-colors-font-lock-keywords
     ,@rainbow-latex-rgb-colors-font-lock-keywords
     ,@rainbow-r-colors-font-lock-keywords
     ,@rainbow-html-colors-font-lock-keywords
     ,@rainbow-html-rgb-colors-font-lock-keywords)))

With these functions defined, call rainbow-mode, and then M-x rainbow-turn-off-words to remove the highlighting from words, and leave it for the hexadecimals. Note that the colours won't change immediately, it will happen next time the buffer is 're-fontified'. You can force this by calling font-lock-fontify-buffer.

You can reset your colors by turning rainbow mode off and on again.

1
  • Thank you very much for the example and the tip!
    – Arktik
    Dec 17, 2020 at 21:01

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.