如何使用活动的迷你缓冲区更改模式行颜色并切换到其他窗口

时间:2013-10-23 14:28:31

标签: emacs elisp

在具有有效迷你缓冲区的同一帧中,任何人都可以想到切换到other-window的方式与minibuffer-exit-hook相似(不带< / em>完全退出迷你缓冲区)?

基本上,我希望当焦点在迷你缓冲区中时,主窗口显示非活动的模式线颜色,然后当我从半边框移动时,将模块更新为活动(对于具有焦点的窗口)使用other-window将活动的迷你缓冲区移动到另一个窗口。

例如,有两个窗口在同一个框架中打开(并排) - 窗口#1是我的笔记 - 窗口#2是我要修改的记录的Big Brother数据库显示。所以我打开迷你缓冲区输入我的记录修改,然后在Window#1和迷你缓冲区中的笔记之间来回切换以复制和粘贴相关部分。当使用other-window在三个区域之间跳转时,仍然很难知道焦点是否在迷你缓冲区或其他窗口中。

Window # 1 (notes)         |     Window # 2 (bbdb record display)
                           |
___________________________|_____________________________________
Name:  lawlist . . .

(defun enter-minibuffer-setup ()
(set-face-attribute 'mode-line nil
    :height 160 :foreground "gray70" :background "black")
(set (make-local-variable 'face-remapping-alist)
    '((default :background "gray10" :foreground "yellow"))))

(defun exit-minibuffer-setup ()
(set-face-attribute 'mode-line nil
    :height 160 :foreground "black" :background "gray70"))

(add-hook 'minibuffer-setup-hook 'enter-minibuffer-setup)

(add-hook 'minibuffer-exit-hook  'exit-minibuffer-setup)

2 个答案:

答案 0 :(得分:1)

一个选项是“adviseother-window函数在切换到迷你缓冲区时执行某种形式。

例如,当您使用other-window循环返回时,以下代码会将迷你缓冲区提示符变为绿色,如果您登陆非迷你缓冲区窗口,则会将提示变为灰色:

(defadvice other-window (after adv-other-window-minibuffer
                               (COUNT &optional ALL-FRAMES))
  "Make minibuffer prompt green when switched to"
  (if (minibufferp)
      (set-face-attribute 'minibuffer-prompt nil
                          :foreground "green" :background "black")
    (set-face-attribute 'minibuffer-prompt nil
                          :foreground "dark grey" :background "black")))

(ad-activate 'other-window)

当然,您不仅限于设置迷你缓冲区提示,但我不清楚您正在尝试实现什么效果。

答案 1 :(得分:0)

更新了草稿 - 从@Carl Groner借用(minibufferp)

(defun enter-minibuffer-setup ()
  (set-face-attribute 'mode-line nil
    :height 160 :foreground "gray70" :background "black")
  (set (make-local-variable 'face-remapping-alist)
    '((default :background "black" :foreground "yellow")))
  (set-face-attribute 'minibuffer-prompt nil
    :background "black" :foreground "cyan"))

(defun exit-minibuffer-setup ()
  (set-face-attribute 'mode-line nil
    :height 160 :foreground "black" :background "gray70")
  (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")
      (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))