After making a new buffer, font-lock-mode could either be enabled on disabled. For instance, if I use (text-mode) or (org-mode) will automatically enable font-lock-mode. However, for (fundamental-mode), font-lock-mode is off.

Solution 1 for colour printing

For printing in colour, I can enable font-lock-mode if it is disabled, then change the colour with (propertize ... 'font-lock-face ...). Finally, disable font-lock-mode as it was originally.

Solution 2 for colour printing

Another solution is to test whether font-lock-mode in on or off.

If font-lock-mode is off, use (propertize ... 'face ...).

If font-lock-mode is on, use (propertize ... 'font-lock-face ...).

Then one can apply both properties, so the then colour will work no matter whether font-lock-mode is on or not.

Is there any particular solution which is preferable over the other?

  • In Solution 2, if font-lock-mode is off, what face are you using in the propertize`?
    – NickD
    Commented Dec 7, 2022 at 20:50
  • I am doing this (insert (propertize "G" 'font-lock-face '(:background "#3D3DFF" :foreground "black"))).
    – Dilna
    Commented Dec 7, 2022 at 21:02
  • The question was: what do you do in the other case? You say: If font-lock-mode is off, use (propertize ... 'face ...) - what face is that?
    – NickD
    Commented Dec 7, 2022 at 21:36
  • It is (insert (propertize "G" 'face '(:background "#3D3DFF" :foreground "black"))).
    – Dilna
    Commented Dec 7, 2022 at 21:42
  • Sorry - I misunderstood.
    – NickD
    Commented Dec 7, 2022 at 21:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.