You can set the face of the header line by setting properties of the text in header-line-format
, but you would need to update header-line-format
on every window switch.
As mentioned by @Slomojo, buffer-list-update-hook
is the hook to use.
You can start with this draft of a hook and adjust the format string and text properties:
(defun my-update-header ()
(mapc
(lambda (window)
(with-current-buffer (window-buffer window)
(if (eq window (selected-window))
(setq header-line-format (propertize "selected" 'face 'mode-line))
(setq header-line-format (propertize "inactive" 'face 'mode-line-inactive)))))
(window-list)))
(add-hook 'buffer-list-update-hook #'my-update-header)
Update Nov 14, 2014:
Here's an extension of the idea used above to arbitrary header formats:
(defun my-update-header ()
(mapc
(lambda (window)
(with-current-buffer (window-buffer window)
;; don't mess with buffers that don't have a header line
(when header-line-format
(let ((original-format (get 'header-line-format 'original))
(inactive-face 'warning)) ; change this to your favorite inactive header line face
;; if we didn't save original format yet, do it now
(when (not original-format)
(put 'header-line-format 'original header-line-format)
(setq original-format header-line-format))
;; check if this window is selected, set faces accordingly
(if (eq window (selected-window))
(setq header-line-format original-format)
(setq header-line-format `(:propertize ,original-format face ,inactive-face)))))))
(window-list)))
I save the original value of header-line-format
as a property of header-line-format
so it can be restored later. To change the face of inactive header lines I use :propertize
.
This breaks if a buffer is displayed by more than one window, and I am convinced that there is no way to do this right: you can't set different buffer-local values of header-line-format
in the selected window and the rest of windows displaying the same buffer. (The mode line gets special treatment in the Emacs redisplay code implemented in C.)