From xemacs-m  Sun Jan 12 14:39:46 1997
Received: from crystal.WonderWorks.COM (crystal.WonderWorks.com [192.203.206.1])
          by xemacs.org (8.8.4/8.8.4) with ESMTP
	  id OAA01185 for <xemacs-beta@xemacs.org>; Sun, 12 Jan 1997 14:39:44 -0600 (CST)
Received: by crystal.WonderWorks.COM 
	id QQbyfi01495; Sun, 12 Jan 1997 15:39:43 -0500 (EST)
Date: Sun, 12 Jan 1997 15:39:43 -0500 (EST)
Message-Id: <QQbyfi01495.199701122039@crystal.WonderWorks.COM>
From: Kyle Jones <kyle_jones@wonderworks.com>
To: xemacs-beta@xemacs.org
Subject: 19.15b90: [PATCH] window.el: shrink-window-if-larger-than-buffer

I got tired of the *Completions* buffer and friends creeping up
in the buffer stack.

By the way, the fact that this function modifies the buffer is
pretty sick.

*** 1.1	1997/01/12 19:44:30
--- window.el	1997/01/12 20:22:47
***************
*** 293,315 ****
  		      ;			       'menu-bar-lines params)
  		      0)))
  	  (unwind-protect
! 	      (progn
! 		(select-window (or window w))
  		(goto-char (point-min))
  		(while (pos-visible-in-window-p
  			(- (point-max)
! 			   (if ignore-final-newline 1 0)))
  		  ;; defeat file locking... don't try this at home, kids!
  		  (setq buffer-file-name nil)
  		  (insert ?\n) (setq n (1+ n)))
  		(if (> n 0)
  		    (shrink-window (min (1- n)
! 					(- (window-height)
! 					   window-min-height)))))
  	    (delete-region (point-min) (point))
  	    (set-buffer-modified-p modified)
  	    (goto-char p)
- 	    (select-window w)
  	    ;; Make sure we unbind buffer-read-only
  	    ;; with the proper current buffer.
  	    (set-buffer buffer))))))
--- 293,318 ----
  		      ;			       'menu-bar-lines params)
  		      0)))
  	  (unwind-protect
! 	      (let ((shrinkee (or window w)))
! 		(set-buffer (window-buffer shrinkee))
  		(goto-char (point-min))
  		(while (pos-visible-in-window-p
  			(- (point-max)
! 			   (if ignore-final-newline 1 0))
! 			shrinkee)
  		  ;; defeat file locking... don't try this at home, kids!
  		  (setq buffer-file-name nil)
  		  (insert ?\n) (setq n (1+ n)))
+ 		(message "n = %d" n)
  		(if (> n 0)
  		    (shrink-window (min (1- n)
! 					(- (window-height shrinkee)
! 					   window-min-height))
! 				   nil
! 				   shrinkee)))
  	    (delete-region (point-min) (point))
  	    (set-buffer-modified-p modified)
  	    (goto-char p)
  	    ;; Make sure we unbind buffer-read-only
  	    ;; with the proper current buffer.
  	    (set-buffer buffer))))))


