From 75bd6843831f02f0dd2ee2c246ba9dee3b81e03f Mon Sep 17 00:00:00 2001 From: John Turner Date: Tue, 12 Sep 2023 00:37:11 -0400 Subject: [PATCH] create library "best-side-window" --- lisp/best-side-window/best-side-window.el | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lisp/best-side-window/best-side-window.el 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 . + +(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: