活动窗口的自定义背景

时间:2009-10-04 16:38:25

标签: emacs text-editor

如何在Emacs中为活动窗口配置不同的背景颜色?

6 个答案:

答案 0 :(得分:9)

如果用“窗口”表示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)

答案 1 :(得分:9)

尝试Yoshida的hiwin模式(可见活动窗口模式):https://github.com/yoshida-mediba/hiwin-mode

答案 2 :(得分:6)

这是使用与背景匹配的模式线非活动颜色的替代方案,因此唯一具有颜色的模式线是活动窗口。我有一个迷你缓冲区进入和退出的钩子,以及切换窗口时。我使用粗体来表示某些类似标题的内容,例如只读和文件名,这样在切换窗口时不同的颜色就不会突出。当我进入迷你缓冲区时,活动窗口模式线变为非活动状态,直到我退出迷你缓冲区,或者当我从一个活动的迷你缓冲区(保持打开状态)切换到另一个窗口时。我必须将模式行背景框设置为匹配。

(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-attributeredisplay期间更改面部的速度太慢。在该上下文中调整面部的首选方法是使用函数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

Example http://www.lawlist.com/images/modeline-example.png

答案 3 :(得分:3)

如果你想要实现的是突出显示当前的缓冲区/帧,我的方法是通过Highlight-Current-Line。它向您显示光标所在的行,但其副作用是它还显示您所在的缓冲区/帧。您可以将其配置为突出显示整个缓冲区,或查看代码以查看它们是如何工作的它

答案 4 :(得分:3)

我认为,

Crosshairs模式是你最好的选择。它不仅引起了对活动窗口的注意,而且还以明显的方式向您显示光标的位置。您可以轻松地打开/关闭它(我将其绑定到C-+。)

您也可以使用crosshairs-toggle-when-idle作为替代方案。直到延迟过去,它才显示十字准线。它也是一个切换。

您当然可以将十字准线与面对面的mode-line脸一起使用。

答案 5 :(得分:3)

我正在使用本主题中建议的hiwin-mode,但是有open issue的shell缓冲区(当处于非活动状态时,文本变得不可见)。

因此,到目前为止,我正在享受的另一个选择是auto-dim-other-buffers mode