6

我想看看是否有办法根据主模式更改模式链接前景色和背景色,

我正在考虑在

(add-hook 'after-change-major-mode-hook

但是,我没有进行这种改变的所有 emacs lisp 经验。这是逻辑:

switch major-mode:
case "emacs-lisp-mode":
  (set-face-foreground 'mode-line "ivory")
  (set-face-background 'mode-line "DarkOrange2")
case "ruby-mode":
  (set-face-foreground 'mode-line "white")
  (set-face-background 'mode-line "red")
...
default:
  (set-face-foreground 'mode-line "black")
  (set-face-background 'mode-line "white")
end switch

提前谢谢了!。

4

2 回答 2

10

你可能想要这样的东西:

(add-hook 'emacs-lisp-mode-hook
          (lambda ()
            (face-remap-add-relative
             'mode-line '((:foreground "ivory" :background "DarkOrange2") mode-line))))

您可能还想对面部使用面部重映射mode-line-inactive

于 2013-04-10T00:55:13.970 回答
3

你所说的“逻辑”是这样的:

(add-hook 'after-change-major-mode-hook 'my-set-mode-line-colors)
(defvar my-mode-line-colors
  '((emacs-lisp-mode :foreground "ivory" :background "DarkOrange2")
    (ruby-mode :foreground "white" :background "red")))
(defun my-set-mode-line-colors ()
  (face-remap-add-relative
   'mode-line (list (or (cdr (assq major-mode my-mode-line-colors))
                        '(:foreground "black" :background "white"))
                    'mode-line)))

或者,您可以按照 Stefan 的建议从特定于模式的钩子中执行此操作。

于 2013-04-09T17:21:02.213 回答