From 5857c6138296743b464d8a748dc40400143bdab4 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Mon, 17 Sep 2012 18:32:41 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + bw.el | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 bw.el diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c531d98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.elc diff --git a/bw.el b/bw.el new file mode 100644 index 0000000..0c4844d --- /dev/null +++ b/bw.el @@ -0,0 +1,100 @@ +;;; bw.el --- Show stuff in a bottom window + +;; Copyright (C) 2012 Tom Willemsen + +;; Author: Tom Willemsen +;; Keywords: convenience +;; Version: 0 + +;; 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 . + +;;; Commentary: + +;; Show stuff in a bottom window. + +;;; Code: + +(defvar bw-last-shown-buffer nil + "The last buffer shown by bw.") + +(defadvice quit-window (around delete-window-perhaps activate) + "Delete the bottom window if necessary." + (let* ((win (window-normalize-window (ad-get-arg 2))) + (delp (and (window-parameter win 'bw-bottom) + (string-match-p "^\\*.*\\*$" + (buffer-name (window-buffer win)))))) + ad-do-it + (when delp + (delete-window win)))) + +(defun bw-create-window () + "Create the bottom window." + (let ((win (split-window (frame-root-window) -20 'below))) + (set-window-parameter win 'bw-bottom t) + ;; Don't allow splitting of the bottom window. + (set-window-parameter win 'split-window (lambda (window size side) nil)) + ;; Don't allow deleting other windows in the bottom window. + (set-window-parameter win 'delete-other-windows (lambda (window) nil)) + win)) + +(defun bw-get-window () + "Try to get the bottom window." + (let (win) + (mapc + (lambda (w) + (when (window-parameter w 'bw-bottom) + (setq win w))) + (window-list)) + win)) + +(defun bw-display-in-bottom-window (buffer alist) + "Show BUFFER in the bottom window, discard ALIST." + (let ((win (or (bw-get-window) (bw-create-window)))) + (set-window-buffer win buffer) + (setq bw-last-shown-buffer buffer) + (local-set-key (kbd "C-c C-q") 'delete-window) + win)) + +(add-to-list 'display-buffer-alist + '("^\\*.*\\*$" . ((bw-display-in-bottom-window . nil)))) +(add-to-list 'window-persistent-parameters (cons 'bw-bottom t)) + +(defun bw-find-appropriate-buffer () + "Find an appropriate buffer for bw." + (let ((buffers (buffer-list)) + tmp-buffer buffer) + (while (and (not buffer) buffers) + (setq tmp-buffer (car buffers)) + (when (string-match-p "^\\*.*\\*$" (buffer-name tmp-buffer)) + (setq buffer tmp-buffer)) + (setq buffers (cdr buffers))) + (unless buffer + (setq buffer "*scratch*")) + buffer)) + +(defun bw-toggle-bottom-window () + "Either show or delete the bottom window." + (interactive) + (let ((win (bw-get-window))) + (if win + (delete-window win) + (setq win (bw-create-window)) + (bw-display-in-bottom-window + (or bw-last-shown-buffer (bw-find-appropriate-buffer)) nil) + (select-window win)))) + +(global-set-key (kbd "") 'bw-toggle-bottom-window) + +(provide 'bw) +;;; bw.el ends here