如何为Emacs中的活动窗口配置不同的背景颜色?
如果用"窗口"表示Emacs对窗口的定义,即窗格,不是真的.
如果通过"窗口"你的意思是其他人的窗口概念,Emacs称之为框架,那么是的.这是一个例子:
(defadvice handle-switch-frame (around switch-frame-set-background)
(set-background-color "white")
ad-do-it
(set-background-color "yellow"))
(ad-activate 'handle-switch-frame)
(defadvice delete-frame (after delete-frame-set-background)
(set-background-color "yellow"))
(ad-activate 'delete-frame)
尝试Yoshida的hiwin模式(可见活动窗口模式):https://github.com/yoshida-mediba/hiwin-mode
这是使用与背景匹配的模式线非活动颜色的替代方案,因此唯一具有颜色的模式行是活动窗口.我有一个迷你缓冲区进入和退出的钩子,以及切换窗口时.我使用粗体来表示某些类似标题的内容,例如只读和文件名,这样在切换窗口时不同的颜色就不会突出.当我进入迷你缓冲区时,活动窗口模式线变为非活动状态,直到我退出迷你缓冲区,或者当我从一个活动的迷你缓冲区(保持打开状态)切换到另一个窗口时.我必须设置模式行背景框以匹配.
(set-face-attribute 'default nil :background "black" :foreground "white" :font "Courier" :height 180) (set-face-attribute 'mode-line nil :height 160 ;; affects everything :foreground "black" :background "gray70") (set-face-attribute 'mode-line-inactive nil :foreground "gray70" :background "black" :box '(:line-width 1 :color "black")) (defun enter-minibuffer-setup () (whitespace-mode t) (set-face-attribute 'mode-line nil :height 160 :foreground "gray70" :background "black" :box '(:line-width 1 :color "black")) (set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "cyan") (set (make-local-variable 'face-remapping-alist) '((default :background "black" :foreground "yellow"))) ) (defun exit-minibuffer-setup () (cond ((or save-as-variable multi-extract-variable multi-attach-variable) (set-face-attribute 'mode-line nil :height 160 :foreground "black" :background "#eab700")) (t (set-face-attribute 'mode-line nil :height 160 :foreground "black" :background "gray70" :box nil))) (set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "cyan")) (add-hook 'minibuffer-setup-hook 'enter-minibuffer-setup) (add-hook 'minibuffer-exit-hook 'exit-minibuffer-setup) (defun lawlist-minibuffer-conditions () (cond ((minibufferp) (set-face-attribute 'mode-line nil :height 160 :foreground "gray70" :background "black" :box '(:line-width 1 :color "black")) (set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "cyan")) (t (set-face-attribute 'mode-line nil :height 160 :foreground "black" :background "gray70") (set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "gray70")) )) (defun lawlist-forward-window () (interactive) (other-window 1) (lawlist-minibuffer-conditions)) (defun lawlist-backward-window () (interactive) (other-window -1) (lawlist-minibuffer-conditions))
替代答案(类似概念): set-face-attribute
对于改变面部来说太慢了redisplay
.在该上下文中调整面的首选方法是使用该函数face-remap-add-relative
; 然而,这个功能使用起来有点复杂,因为面孔一个接一个地堆叠起来并被遮蔽.因此,我需要修改以下草案备选答案(将来)以便合并face-remap-add-relative
- 在此期间,我face-remapping-alist
手动设置(根据手册/ doc-string,这不是首选方法).
(defvar modeline-selected-window nil)
(let ((default-background (face-background 'default nil 'default)))
(set-face-attribute 'mode-line-inactive nil :background default-background :box nil))
(defun modeline-record-selected-window ()
(setq modeline-selected-window (selected-window)))
(defun modeline-update-function ()
(cond
((minibufferp)
(let ((default-background (face-background 'default nil 'default)))
(with-selected-window (minibuffer-window)
(setq-local face-remapping-alist '(
(default :foreground "blue")
(minibuffer-prompt :foreground "red"))))
(setq-default face-remapping-alist `((mode-line ,'mode-line-inactive)))))
(t
(with-selected-window (minibuffer-window)
(when (local-variable-p 'face-remapping-alist)
(kill-local-variable 'face-remapping-alist)))
(setq-default face-remapping-alist nil))))
(defun modeline-set-format ()
(setq mode-line-format '(
(:eval
(if (eq modeline-selected-window (selected-window))
(propertize "SELECTED WINDOW" 'face 'font-lock-warning-face)
(propertize "NOT-SELECTED WINDOW" 'face 'font-lock-keyword-face)))))
;; next two lines make the affect immediately apparent
(setq modeline-selected-window (selected-window))
(force-mode-line-update))
(define-minor-mode modeline-mode
"This is a minor-mode for `modeline-mode`."
:init-value nil
:lighter " ML"
:keymap nil
:global t
:group nil
(cond
(modeline-mode
(add-hook 'post-command-hook 'modeline-record-selected-window)
(add-hook 'buffer-list-update-hook 'modeline-update-function)
(add-hook 'text-mode-hook 'modeline-set-format)
(when (called-interactively-p 'any)
(message "Globally turned ON `modeline-mode`.")))
(t
(remove-hook 'post-command-hook 'modeline-record-selected-window)
(remove-hook 'buffer-list-update-hook 'modeline-update-function)
(remove-hook 'text-mode-hook 'modeline-set-format)
(when (called-interactively-p 'any)
(message "Globally turned OFF `modeline-mode`.") ))))
(modeline-mode 1) ;; globally turn on minor-mode
示例http://www.lawlist.com/images/modeline-example.png