2

Is it possible to set both global and buffer-local values for the face-remapping-alist?

The mode-line requires a global value to effectively change the color. To change the colors of the background and foreground of the default within the mini-buffer, a local value is needed. Setting a global value cancels out the buffer-local value, and visa versa.

I am trying to avoid using set-face-attribute and set-face-background and set-face-foreground due to the problems discussed in the thread of the following link: How to speed-up a custom mode-line face change function in Emacs Using the face-remapping-alist avoids those issues.

(defun my-modeline-face-function ()
  (cond
    ((minibufferp)
      (with-selected-window (minibuffer-window)
        (set (make-local-variable 'face-remapping-alist) '(
          (default :background "black" :foreground "yellow")
          (minibuffer-prompt :background "black" :foreground "cyan" :weight bold) 
          (mode-line :height 140 :foreground "gray70" :background "black" :box nil)))))
    (t
        (with-selected-window (minibuffer-window)
          (set (make-local-variable 'face-remapping-alist) '(
            (default :background "black" :foreground "grey50")
            (minibuffer-prompt :background "black" :foreground "white")
            (mode-line :height 140 :foreground "black" :background "gray70" :box nil)))) )))

EDIT (August 5, 2014):  Here is the working revision based upon the helpful answer of @phils below:

(defun my-modeline-face-function ()
  (cond
    ((minibufferp)
      (with-selected-window (minibuffer-window)
        (setq-local face-remapping-alist '(
          (default :background "black" :foreground "yellow")
          (minibuffer-prompt :background "black" :foreground "cyan" :weight bold) )))
      (setq-default face-remapping-alist '(
        (mode-line :height 140 :foreground "gray70" :background "black" :box nil))))
    (t
        (with-selected-window (minibuffer-window)
          (setq-local face-remapping-alist '(
            (default :background "black" :foreground "grey50")
            (minibuffer-prompt :background "black" :foreground "white"))))
      (setq-default face-remapping-alist '(
        (mode-line :height 140 :foreground "black" :background "gray70" :box nil) )))))
Community
  • 1
  • 1
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • I've never used it, but it seems like it should be possible. Another possibility would be just to `let` bind it in your conditions, which I believe would temporarily override the global setting. – Dan Aug 05 '14 at 22:05

1 Answers1

3

Is it possible to set both global and buffer-local values...?

Yes:

(setq-local foo "local")
(setq-default foo "global")

Setting a global value cancels out the buffer-local value, and visa versa.

Setting the default/global value for a variable has no effect on any buffer-local values, so I'm not sure what you meant by that?

Similarly, setting a buffer-local value has no effect on the global value (although it does, of course, then proceed to shadow the global value for most evaluations). You can obtain the global value with (default-value SYMBOL)

phils
  • 71,335
  • 11
  • 153
  • 198