Emacs: Set background color for specific window

Is it possible to set the background color of a specific emacs window?

I am using the "dedicated window" functionality to pin an emacs buffer to a frame. However, I also want that window to be recognizable as a dedicated window.

Currently I am using buffer-face-mode to set a buffer-specific default font with a slightly darker background color. However, this formatting also applies to windows viewing the same buffer, that are not dedicated to the buffer. Being able to set the font on a per-window basis would remove that problem.


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


What you want is to specify the buffer as being "special-display". That does just what you want.

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

  • special-display-regexps
  • special-display-buffer-names
  • That's the easy way. Emacs likes to consider these options obsolete since release 24.3, and it recommends that you use the incredibly complicated option display-buffer-alist instead.

    This is all I do, to have all buffers with names that start and end with * to be displayed in their own, dedicated frames:

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

    To get special-display frames to have different properties (ie, frame parameters), such as a different color background, customize option special-display-frame-alist .

    This is essentially the definition I use:

    (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 options.


    The method that worked for me in Emacs 25.1.1 was using the face-remapping-alist variable. When the buffer is initialized, modify the :background attribute of the default face to the color you want. Eg, I make the background color of my Treemacs buffer different than everything 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)
    
    链接地址: http://www.djcxy.com/p/63866.html

    上一篇: 在Emacs中锁定和字符串字面着色

    下一篇: Emacs:为特定窗口设置背景颜色