blob: 12118fad6d683a416553011695b755c588c6d88a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
;;; best-side-window.el --- -*- lexical-binding: t; -*-
;; Copyright John Turner (C) 2023
;; Author: John Turner
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(require 'cl-lib)
(defgroup best-side-window nil "Select ideal side to display buffer")
(defcustom -default-side 'bottom
"Default side to display buffer if -choose-best-side-functions fails to choose a side")
(defcustom -choose-best-side-functions nil
"The first non-nil return value will be used as the side to use for display buffer")
(defun -best-side ()
(cl-loop for f in -choose-best-side-functions
for result = (funcall f)
if result
return result))
(defun -display-buffer-in-best-side-window (buffer alist)
(let ((side (or (-best-side) -default-side)))
(display-buffer-in-side-window buffer (cons (cons 'side side) alist))))
(defun -bottom-when-frame-split ()
(if (< (frame-pixel-width) (/ (display-pixel-width) 2))
'bottom
-default-side))
(add-to-list '-choose-best-side-functions '-bottom-when-frame-split)
(provide 'best-side-window)
;;; best-side-window.el ends here
;; Local Variables:
;; read-symbol-shorthands: (("-" . "best-side-window-"))
;; End:
|