Skip to content

Instantly share code, notes, and snippets.

@milljm
Last active March 12, 2020 14:10
Show Gist options
  • Save milljm/f17548b63075749f08e2c6a19c106c31 to your computer and use it in GitHub Desktop.
Save milljm/f17548b63075749f08e2c6a19c106c31 to your computer and use it in GitHub Desktop.
Inverse line highlighting in Emacs (highlight the line you *were* on in the *other* buffer)
;; Highlight line for _inactive_ windows ::
;; Credit to https://emacs.stackexchange.com/questions/14638/change-highlight-color-when-window-isnt-in-focus
;; Answerer: https://emacs.stackexchange.com/users/780/glucas
(require 'hl-line)
(set-face-background hl-line-face "#333")
(defface hl-line-inactive
'((t nil))
"Inactive variant of `hl-line'."
:group 'hl-line)
(defun hl-line-update-face (window)
"Update the `hl-line' face in WINDOW to indicate whether the window is selected."
(with-current-buffer (window-buffer window)
(when hl-line-mode
(if (not (eq (current-buffer) (window-buffer (selected-window))))
(face-remap-reset-base 'hl-line)
(face-remap-set-base 'hl-line (face-all-attributes 'hl-line-inactive))
)
)
)
)
(add-hook 'buffer-list-update-hook (lambda () (walk-windows #'hl-line-update-face nil t)))
(add-hook 'find-file-hook 'hl-line-mode)
(add-hook 'after-change-major-mode-hook 'hl-line-mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment