简体   繁体   English

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

[英]How to change modeline color with active minibuffer and switch to other-window

Within the same frame and with an active minibuffer, can anyone think of a way to have switch to other-window behave similar to a minibuffer-exit-hook ( without completely exiting the minibuffer)? 在同一个帧中并且具有活动的微型缓冲区,有人能想到一种切换到other-window方式类似于minibuffer-exit-hook而不必完全退出微型缓冲区)吗?

Essentially, I'd like to have the main windows show an inactive modeline color when focus is in the minibuffer, and then update the modline to active (for a window that has focus) when I move from the semi-active minibuffer to another window using other-window . 本质上,我希望主窗口在微型缓冲区中有焦点时显示不活动的Modeline颜色,然后在我从半活动微型缓冲区移至另一个窗口时将modline更新为活动(对于具有焦点的窗口)使用other-window

For example, there are two windows open in the same frame (side by side) -- Window # 1 are my notes -- Window # 2 is a Big Brother Database display of a record that I want to modify. 例如,在同一帧中(并排)有两个窗口打开-窗口#1是我的笔记-窗口#2是我要修改的记录的Big Brother数据库显示。 So I open the minibuffer to input my record modification and then switch back and forth between my notes in Window # 1 and the minibuffer to copy and paste the relevant portions. 因此,我打开迷你缓冲区以输入我的记录修改,然后在窗口#1中的笔记和迷你缓冲区之间来回切换以复制和粘贴相关部分。 When using other-window to jump between the three areas, it is still difficult to know whether focus is in the minibuffer or another window. 当使用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)

One option would be to " advise " the other-window function to execute some form when switching to the minibuffer. 一种选择是“ 建议other-window函数在切换到迷你缓冲区时执行某种形式。

For example, the following code will turn the minibuffer prompt green when you cycle back to it using other-window , and if you land on a non minibuffer window it turns the prompt grey: 例如,以下代码将在您使用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)

Of course you are not limited to just setting the minibuffer prompt, but it's not clear to me exactly what effect your are trying to achieve. 当然,您不仅限于设置minibuffer提示符,但我不清楚您到底想达到什么效果。

Updated draft -- borrowing (minibufferp) from @Carl Groner 更新的草案-从@Carl Groner借用(minibufferp) minibufferp (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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM