;;; dispb.el --- display buffer hacks! ;; Copyright (C) 2002 by Taiki SUGAWARA ;; Author: Taiki SUGAWARA ;; Keywords: tool ;; This file 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 2, or (at your option) ;; any later version. ;; This file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Code: (defun dispb-get-widest-window () (let (win) (walk-windows (lambda (w) (when (and (not (window-minibuffer-p w)) (or (not win) (>= (window-width w) (window-width win)))) (setq win w)))) win)) (defun dispb-hack-display-buffer (orig-win new-win conf &optional select-orig-win-p) (let (widest buf) (setq widest (dispb-get-widest-window)) (when (> (window-width widest) (window-width new-win)) (setq buf (window-buffer new-win)) (set-window-configuration conf) (select-window widest) (unless (window-minibuffer-p orig-win) (select-window (split-window-vertically))) (switch-to-buffer buf) (and select-orig-win-p (select-window orig-win))))) (defadvice display-buffer (around dispb-ad activate) (let ((orig-win (selected-window)) (conf (current-window-configuration)) (win ad-do-it)) (dispb-hack-display-buffer orig-win win conf t))) (defadvice pop-to-buffer (around dispb-ad activate) (let ((orig-win (selected-window)) (conf (current-window-configuration)) win) ad-do-it (setq win (selected-window)) (dispb-hack-display-buffer orig-win win conf))) (defun dispb-temp-buffer-show-function (buf) (display-buffer buf) (with-current-buffer buf (run-hooks 'temp-buffer-show-hook))) (setq temp-buffer-show-function 'dispb-temp-buffer-show-function) (provide 'dispb) ;;; dispb.el ends here