Emacs: setting the background color for a specific window

Can I set the background color for a specific emacs window?

I use the "dedicated window" function to bind the emacs buffer to the frame. However, I also want this window to be recognized as a highlighted window.

I am currently using buffer-face-mode to set the default font for a particular buffer with a slightly dark background. However, this formatting also applies to windows looking at the same buffer that are not intended for the buffer. The ability to set a font for each window can fix this problem.

+4
source share
3 answers

Doing this for one specific window is not a feature supported by Emacs right now. OTOH, you can do this for a specific frame, so if your window is inside a single-window frame (as is often the case for selected windows), you can definitely set the background-color frame parameter (and should be able to set it directly from display-buffer-alist or special-display-regexps .

+3
source

You want to specify the buffer as a "special display". It does what you want.

You can configure one or both of these options (variables):

  • special-display-regexps
  • special-display-buffer-names

This is an easy way. Emacs loves to consider these options obsolete since the release of 24.3, and recommends using the incredibly complex display-buffer-alist option instead.

This is all I do so that all buffers with names that start and end with * are displayed in their own allocated frames:

 (setq special-display-regexps '("[ ]?[*][^*]+[*]")) 

To get special display frames that have different properties (for example, frame parameters), for example, a different colored background, configure the special-display-frame-alist parameter.

This is essentially the definition I'm using:

 (setq special-display-alist '((font . "-*-Lucida Console-normal-r-*-*-14-*-*-*-c-*-iso8859-1") (width . 80) (height . 14) (mouse-color . "Yellow") (cursor-color . "Yellow") (menu-bar-lines . 1) (foreground-color . "Black") (background-color . "LightSteelBlue") (top . 0) (left . 0) (unsplittable . t) (user-position . t) (vertical-scroll-bars . right))) 

But I recommend that you use Customize to set the value of all such parameters.

0
source

The method that worked for me in Emacs 25.1.1 used the variable face-remapping-alist . When the buffer is initialized, change the :background attribute of the default face to the color you want. For example, I am making the background color of my Treemacs buffer different than anything else by adding something like this to my .emacs file:

 (defun treemacs-mode-handler() (set (make-local-variable 'face-remapping-alist) '((default :background "#303030")))) (add-hook 'treemacs-mode-hook 'treemacs-mode-handler) 
0
source

Source: https://habr.com/ru/post/1484192/


All Articles