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.

fegax
  • 35
  • 5
  • 1
    Does this answer your question? [How to modify-face for a specific buffer?](https://emacs.stackexchange.com/questions/7281/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 '22 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 '22 at 08:59
  • Why are you suggesting to close this question, when it is not working ;( ? – fegax Jul 17 '22 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 '22 at 14:35
  • The face name that you are interested in changing is called `default`. The linked example uses the face name `stripe-highlight`. Consider substituting the latter with the former ... – lawlist Jul 17 '22 at 15:11
  • 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 '22 at 15:41

1 Answers1

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.