I recently started using flycheck-mode in Emacs. I generally run Emacs with one large full-screen window, and I wanted to split it so that there's a single short long window at the top of the screen for my flycheck errors which would never have another buffer replace it or be split. So I wrote this function and hook to ensure that. Note that it needs to run in the refresh hook, not the mode hook, because the mode gets turned on before the window gets created.
Last active
September 16, 2015 00:34
-
-
Save glasser/e8363df7640f2c445460 to your computer and use it in GitHub Desktop.
Preserving Emacs flycheck's error window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defconst top-window-height 10 "Height to set top window to when splitting") | |
(defun ensure-top-window () | |
(interactive) | |
(let* ((w (selected-window)) | |
(is-top (and | |
(eq (window-parent w) (frame-root-window)) | |
(eq (window-top-child (frame-root-window)) w)))) | |
; Make sure we're the top window, and default our height to | |
; top-window-height. This is a little destructive (loses all window state) | |
; but generally only happens once per session. | |
(when (not is-top) | |
(delete-other-windows) | |
(split-window-below top-window-height) | |
(set-window-buffer (window-next-sibling w) "*scratch*")) | |
; Don't let anybody split us horizontally. | |
(setq window-size-fixed 'width) | |
; Don't let anybody put anything else inside us. | |
(set-window-dedicated-p w t))) | |
; Make sure that the flycheck error list won't be split horizontally or have | |
; something else be put in it. Note that this isn't a | |
; flycheck-error-list-mode-hook because that runs before the window is created. | |
(add-hook 'flycheck-error-list-after-refresh-hook | |
(lambda () | |
(with-selected-window (flycheck-get-error-list-window t) | |
(ensure-top-window)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment