当前位置:  开发笔记 > 后端 > 正文

活动窗口的自定义背景

如何解决《活动窗口的自定义背景》经验,为你挑选了3个好方法。

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



1> Nicholas Ril..:

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


我的意思是Emacs窗口.模式线的亮点对我来说还不够.我使用大屏幕,很多窗户都打开..而且我经常开始编辑而不是我想要编辑的窗口.我会尝试反向视频模式会有所改善

2> semente..:

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



3> lawlist..:

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

(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

推荐阅读
wurtjq
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有