From xemacs-m  Sun Jan 12 16:33:05 1997
Received: from jupiter.scs.Ryerson.CA (root@jupiter.scs.Ryerson.CA [141.117.18.31])
          by xemacs.org (8.8.4/8.8.4) with SMTP
	  id QAA02362 for <xemacs-beta@xemacs.org>; Sun, 12 Jan 1997 16:33:04 -0600 (CST)
Received: from jupiter.scs.Ryerson.CA by jupiter.scs.Ryerson.CA via suspension id <10637(1)>; Sun, 12 Jan 1997 17:33:02 -0500
Received: from jupiter.scs.Ryerson.CA by jupiter.scs.Ryerson.CA id <10634(1)>; Sun, 12 Jan 1997 17:32:54 -0500
From: Dave Mason <dmason@scs.Ryerson.CA>
To: xemacs-beta@xemacs.org
Subject: Re: 19.15b90: [PATCH] window.el: shrink-window-if-larger-than-buffer
In-Reply-To: <QQbyfi01495.199701122039@crystal.WonderWorks.COM>
References: <QQbyfi01495.199701122039@crystal.WonderWorks.COM>
X-Face: %Q_F^9R-:'3MM7eZ6@E.x@f\*bgatzGv-8d%I~L[p^.F)3QF{kq\UTsu|e#?)3FPwJNvPPB
 !s*He|-*M^p*~bh"Nywm5NLL\\Rl3r(hWHY*F:$/RdKV*bS";n&#\Ov@*=]mu\}6tP<lkW*7FT|:Dm
 9ejO^{)GHJdPQaa"C\<Ak`K27?328'V(u*|jAEZR9-z!o\^j:Cb&*tx_9\KbXD*2
Message-Id: <97Jan12.173254edt.10634(1)@jupiter.scs.Ryerson.CA>
Date: 	Sun, 12 Jan 1997 17:32:53 -0500

Kyle Jones wrote:
> 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.

Bleah!!!

I removed the inserts, which removes the need for unwind-protect, and
a whole pile of other stuff.  And the whole (or window w) is junk
because it's already done at the beginning of the function.

Maybe I'm missing something big here, but there seems to be a huge
amount of cruft in this code!

This is diff'ed against 19.14.

Somebody better try this code before throwing it in.  I'm nervous
removing 1/2 the code in something that's been there for a long time.
I also didn't have as many places to try it, as 19.14 doesn't use it
for help buffers, but it works where I tried it.  This is the kind of
place where there *might* be an off-by-one error.

../Dave

*** window.el.orig	Sun Jan 12 16:05:54 1997
--- window.el	Sun Jan 12 17:19:32 1997
***************
*** 260,278 ****
    (or window (setq window (selected-window)))
    (save-excursion
      (set-buffer (window-buffer window))
!     (let* ((w (selected-window))	;save-window-excursion can't win
! 	   (buffer-file-name buffer-file-name)
! 	   (p (point))
! 	   (n 0)
! 	   (ignore-final-newline
! 	    ;; If buffer ends with a newline, ignore it when counting height
! 	    ;; unless point is after it.
! 	    (and (not (eobp))
! 		 (eq ?\n (char-after (1- (point-max))))))
! 	   (buffer-read-only nil)
! 	   (modified (buffer-modified-p))
! 	   (buffer (current-buffer))
! 	   (mini (frame-property (window-frame window) 'minibuffer))
  	   (edges (window-pixel-edges (selected-window))))
        (if (and (< 1 (let ((frame (selected-frame)))
  		      (select-frame (window-frame window))
--- 260,266 ----
    (or window (setq window (selected-window)))
    (save-excursion
      (set-buffer (window-buffer window))
!     (let* ((mini (frame-property (window-frame window) 'minibuffer))
  	   (edges (window-pixel-edges (selected-window))))
        (if (and (< 1 (let ((frame (selected-frame)))
  		      (select-frame (window-frame window))
***************
*** 292,318 ****
  		      ;FSFmacs (frame-property (window-frame window)
  		      ;			       '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))))))
  
  (defun backward-other-window (arg &optional all-frames device)
    "Select the ARG'th different window on this frame, going backwards.
--- 280,296 ----
  		      ;FSFmacs (frame-property (window-frame window)
  		      ;			       'menu-bar-lines params)
  		      0)))
! 	(let* ((height (window-height window))
! 	       (n (max window-min-height
! 		       (- height
! 			  (progn
! 			    (goto-char (point-min))
! 			    (forward-line height))
! 			  -1))))
! 	  (if (< n height)
! 	      (shrink-window (- height n)
! 			     nil
! 			     window)))))))
  
  (defun backward-other-window (arg &optional all-frames device)
    "Select the ARG'th different window on this frame, going backwards.

