1

Emacs css-mode is fontifying my colour literals. For example:

Two colour literals coloured

This makes the text harder to read.

I tried to defeat it with the following in my .emacs. (Note: this matches on ‘hsl’ because those are the only literals I actually use.)

(font-lock-add-keywords nil
 '(
   ("color: *\\(hsla?(.*)\\)" 1 'default t) ; Colour literal
   )
 )

This fails. I can override the fontification of other things, but somehow these colour literals are override proof.

How can I defeat this unwanted fontification?

  • 2
    I'm not on my computer right now, but I'd start by looking in the customization group for CSS mode. There's a very big chance the feature you want to disable is not a product of font-lock activity, but is done afterwards. – wvxvw Dec 16 '18 at 6:51
  • @wvxvw I never use the customization UI. But now I see what to look for in the .el: ‘defcustom’. Thank you. – Michael Allan Dec 16 '18 at 14:14
  • @MichaelAllan Whether you use customize-group, apropos-variable, or just completion in describe-variable, you have several good methods for discovering which options are available without resorting to searching for defcustom in the .el file. Obviously you can do that, but it probably shouldn't be your first port of call. – phils Dec 16 '18 at 21:28
2

M-x customize-group RET css RET

would inform you about:

C-hv css-fontify-colors

css-fontify-colors is a variable defined in `css-mode.el'.
Its value is t

  This variable is safe as a file local variable if its value
  satisfies the predicate `booleanp'.

Documentation:
Whether CSS colors should be fontified using the color as the background.
When non-`nil', a text representing CSS color will be fontified
such that its background is the color itself.  E.g., #ff0000 will
be fontified with a red background.

You can customize this variable.

This variable was introduced, or its default value was changed, in
version 26.1 of Emacs.

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.