0

Let's say I want my file notes.org to have a specific background color. How to do that? But I want other files to adhere to the standard theme color for background.

So, I want yellow background for notes.org but the theme background color for everything else.

It should be something simple, but I can't find the way how to do it.

I would prefer a way I can set it via elisp code in my init (.spacemacs) file. Preferably without the need to create a custom theme just for one file etc. The least favorite option is to put it in # Local Variables eval but if the only way it's possible is this way, I will be thankful for even that solution.

6
  • 1
    Does this answer your question? How to modify-face for a specific buffer? Perhaps try using something like the following code snippet and combine it with the same approach as in the accepted answer of the related linked thread: (add-hook 'org-mode-hook (lambda () (when (string-match "notes\\.org$" buffer-file-name) (face-remap-add-relative ...)))) The face at issue is named default and the spec is :background.
    – lawlist
    Jul 16, 2022 at 16:29
  • @lawlist I have tried this: (add-hook 'org-mode-hook (lambda () (when (string-match "notes\\.org$" buffer-file-name) (face-remap-add-relative 'stripe-highlight '(:foreground "black" :background "yellow"))))) but it is not working. The background is still white in notes.org. ;(
    – fegax
    Jul 17, 2022 at 8:59
  • Why are you suggesting to close this question, when it is not working ;( ?
    – fegax
    Jul 17, 2022 at 14:35
  • I can't find anywhere solution for this. Please, if somebody know what to do change in the code, let me know. Thank you.
    – fegax
    Jul 17, 2022 at 14:35
  • 1
    (add-hook 'org-mode-hook (lambda () (when (and (not (null buffer-file-name)) (string-match-p "notes\\.org$" buffer-file-name)) (face-remap-add-relative 'default '(:foreground "black" :background "yellow")))))
    – lawlist
    Jul 17, 2022 at 15:41

1 Answer 1

1

To get this

Change color of just a single buffer

do this

  1. C-x C-f somefile.org
  2. Add the following three lines to very end of file
# Local Variables:
# eval: (face-remap-add-relative 'default :foreground "black" :background "yellow")
# End:

  1. C-x C-s. Do M-x revert-buffer RET.
  2. Profit.

If the file of interest is in some other mode, and not org-mode the above suggestion will not work. In that case, use

M-x add-file-local-variable RET eval RET (face-remap-add-relative 'default :foreground "black" :background "yellow") RET

Save the file. Kill the buffer. Re-open the file.

2
  • Instead of killing the buffer and reopening it, just call normal-mode.
    – db48x
    Jul 18, 2022 at 5:22
  • Yes. Thanks. Today I learnt about normal-mode.
    – user31220
    Jul 18, 2022 at 5:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.