如何为`face-remapping-alist`设置缓冲区本地值和全局值

时间:2014-08-05 21:39:48

标签: emacs elisp

是否可以为face-remapping-alist设置全局缓冲区本地值?

mode-line需要全局值才能有效地更改颜色。要更改迷你缓冲区中default的背景和前景的颜色,需要本地值。设置全局值会取消缓冲区本地值,反之亦然。

由于以下链接的主题中讨论的问题,我试图避免使用set-face-attributeset-face-background以及set-face-foregroundHow to speed-up a custom mode-line face change function in Emacs使用face-remapping-alist避免这些问题。

  
(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)))) )))

编辑(2014年8月5日):以下是基于@phils的有用答案的工作修订:

  
(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) )))))

1 个答案:

答案 0 :(得分:3)

  

是否可以设置全局和缓冲区本地值......?

是:

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

  

设置全局值会取消缓冲区本地值,反之亦然。

设置变量的默认/全局值对任何缓冲区本地值都没有影响,所以我不确定你的意思是什么?

类似地,设置缓冲区本地值对全局值没有影响(当然,它确实会影响大多数评估的全局值)。您可以使用(default-value SYMBOL)

获取全局值