Skip to content

Instantly share code, notes, and snippets.

@mpontus
Created April 1, 2015 15:36
Show Gist options
  • Select an option

  • Save mpontus/3526f886c494a9e2b5b9 to your computer and use it in GitHub Desktop.

Select an option

Save mpontus/3526f886c494a9e2b5b9 to your computer and use it in GitHub Desktop.
(defun display-buffer-above-selected (buffer alist)
"Try displaying BUFFER in a window below the selected window.
This either splits the selected window or reuses the window below
the selected one."
(let (window)
(or (and (setq window (window-in-direction 'above))
(eq buffer (window-buffer window))
(window--display-buffer buffer window 'reuse alist))
(and (not (frame-parameter nil 'unsplittable))
(let ((split-height-threshold 0)
split-width-threshold)
(setq window (selected-window))
(select-window (window--try-to-split-window window alist)))
(window--display-buffer
buffer window 'window alist display-buffer-mark-dedicated))
(and (setq window (window-in-direction 'above))
(not (window-dedicated-p window))
(window--display-buffer
buffer window 'reuse alist display-buffer-mark-dedicated))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment