Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight current active window

Tags:

emacs

Is there an easy way to change the background color of the active window to easily distinguish which window has the input?

I know of hiwin-mode (https://github.com/masutaka/hiwin-mode). But this mode has problems playing nicely with helm.

I also know of color-theme-buffer-local (https://github.com/vic/color-theme-buffer-local) and I am wondering if it can be customized to do what I want.

like image 548
Tohiko Avatar asked Oct 18 '15 06:10

Tohiko


Video Answer


2 Answers

auto-dim-other-buffers.el

You might want to take a look at auto-dim-other-buffers.el, available from MELPA.

The auto-dim-other-buffers-mode is a global minor mode which makes non-current buffer less prominent making it more apparent which window has a focus.

The preferred way to install the mode is by installing a package from MELPA:

M-x package-install RET auto-dim-other-buffers RET

Once installed, the mode can be turned on (globally) with:

M-x auto-dim-other-buffers-mode RET

To make the mode enabled every time Emacs starts, add the following to Emacs initialisation file (~/.emacs or ~/.emacs.d/init.el):

(add-hook 'after-init-hook (lambda ()
  (when (fboundp 'auto-dim-other-buffers-mode)
    (auto-dim-other-buffers-mode t))))

To configure how dimmed buffers look like, customise auto-dim-other-buffers-face. This can be accomplished by:

M-x customize-face RET auto-dim-other-buffers-face RET

The auto-dim-other-buffers-mode is a global minor mode which makes non-current buffer less prominent making it more apparent which window has a focus.

For a given active window, all other windows that does not show the same buffer will be set to a custom background. I.e., active window and other windows showing the same buffer will have a background color that differs from the rest of the windows. I believe this last part is the specific behaviour you are looking for, based on your comment to the accepted answer.

"Thank you very much. This is very close to what I want. Except for the fact that having two windows opening the same buffer cause both windows to be marked as 'inactive'. It's not super important, but is there an easy way to resolve this?"

like image 145
dfrib Avatar answered Sep 21 '22 01:09

dfrib


(defun highlight-selected-window ()
  "Highlight selected window with a different background color."
  (walk-windows (lambda (w)
                  (unless (eq w (selected-window)) 
                    (with-current-buffer (window-buffer w)
                      (buffer-face-set '(:background "#111"))))))
  (buffer-face-set 'default))

(add-hook 'buffer-list-update-hook 'highlight-selected-window)

Change the background color ("#111") to suit your taste.

like image 35
huaiyuan Avatar answered Sep 20 '22 01:09

huaiyuan