summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2023-09-12 00:37:11 -0400
committerJohn Turner <jturner.usa@gmail.com>2023-09-12 00:37:11 -0400
commit75bd6843831f02f0dd2ee2c246ba9dee3b81e03f (patch)
tree0b11e693c62b5c4ad24e3c8137446865bfcaad93 /lisp
parent9ca94c1fc48b8e97f9ee78c2a978572a73e23d3f (diff)
downloademacs.d-75bd6843831f02f0dd2ee2c246ba9dee3b81e03f.tar.gz
create library "best-side-window"
Diffstat (limited to 'lisp')
-rw-r--r--lisp/best-side-window/best-side-window.el52
1 files changed, 52 insertions, 0 deletions
diff --git a/lisp/best-side-window/best-side-window.el b/lisp/best-side-window/best-side-window.el
new file mode 100644
index 0000000..12118fa
--- /dev/null
+++ b/lisp/best-side-window/best-side-window.el
@@ -0,0 +1,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: