comparison lisp/window.el @ 4364:69e5c2373d37

(shrink-window-if-larger-than-buffer): Do nothing if the window is the only window of its frame. If the buffer ends in newline and point is not at the end of the buffer, don't display last (empty) line.
author Richard M. Stallman <rms@gnu.org>
date Sat, 31 Jul 1993 01:08:48 +0000
parents dc73f3152d2f
children 4f8cf717fca0
comparison
equal deleted inserted replaced
4363:f593b231193f 4364:69e5c2373d37
137 (shrink-window arg t)) 137 (shrink-window arg t))
138 138
139 (defun shrink-window-if-larger-than-buffer (&optional window) 139 (defun shrink-window-if-larger-than-buffer (&optional window)
140 "Shrink the WINDOW to be as small as possible to display its contents. 140 "Shrink the WINDOW to be as small as possible to display its contents.
141 Do nothing if the buffer contains more lines than the present window height, 141 Do nothing if the buffer contains more lines than the present window height,
142 or if some of the window's contents are scrolled out of view." 142 or if some of the window's contents are scrolled out of view,
143 or if the window is the only window of its frame."
143 (interactive) 144 (interactive)
144 (save-excursion 145 (save-excursion
145 (set-buffer (window-buffer window)) 146 (set-buffer (window-buffer window))
146 (let ((w (selected-window)) ;save-window-excursion can't win 147 (let ((w (selected-window)) ;save-window-excursion can't win
147 (buffer-file-name buffer-file-name) 148 (buffer-file-name buffer-file-name)
148 (p (point)) 149 (p (point))
149 (n 0) 150 (n 0)
151 (ignore-final-newline
152 ;; If buffer ends with a newline, ignore it when counting height
153 ;; unless point is after it.
154 (and (not (eobp))
155 (eq ?\n (char-after (1- (point-max))))))
150 (window-min-height 0) 156 (window-min-height 0)
151 (buffer-read-only nil) 157 (buffer-read-only nil)
152 (modified (buffer-modified-p)) 158 (modified (buffer-modified-p))
153 (buffer (current-buffer))) 159 (buffer (current-buffer)))
154 (if (pos-visible-in-window-p (point-min)) 160 (if (and (< 1 (count-windows))
161 (pos-visible-in-window-p (point-min)))
155 (unwind-protect 162 (unwind-protect
156 (progn 163 (progn
157 (select-window (or window w)) 164 (select-window (or window w))
158 (goto-char (point-min)) 165 (goto-char (point-min))
159 (while (pos-visible-in-window-p (point-max)) 166 (while (pos-visible-in-window-p
167 (- (point-max)
168 (if ignore-final-newline 1 0)))
160 ;; defeat file locking... don't try this at home, kids! 169 ;; defeat file locking... don't try this at home, kids!
161 (setq buffer-file-name nil) 170 (setq buffer-file-name nil)
162 (insert ?\n) (setq n (1+ n))) 171 (insert ?\n) (setq n (1+ n)))
163 (if (> n 0) (shrink-window (1- n)))) 172 (if (> n 0) (shrink-window (1- n))))
164 (delete-region (point-min) (point)) 173 (delete-region (point-min) (point))