aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-07-01 07:07:44 +0000
committerRichard M. Stallman1997-07-01 07:07:44 +0000
commit93289e14f2aa161c5692b395fa728a2c7331be5a (patch)
tree066fb69ba70f53985289818c522fe080a2661cd6
parentc55db078cf3f2518fb9cb961363816e226f24dc0 (diff)
downloademacs-93289e14f2aa161c5692b395fa728a2c7331be5a.tar.gz
emacs-93289e14f2aa161c5692b395fa728a2c7331be5a.zip
(shrink-window-if-larger-than-buffer):
Use compute-motion, instead of inserting newlines.
-rw-r--r--lisp/window.el89
1 files changed, 38 insertions, 51 deletions
diff --git a/lisp/window.el b/lisp/window.el
index a47a1eaac0b..2ac97ffd62c 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -239,57 +239,44 @@ or if the window is not the full width of the frame,
239or if the window is the only window of its frame." 239or if the window is the only window of its frame."
240 (interactive) 240 (interactive)
241 (or window (setq window (selected-window))) 241 (or window (setq window (selected-window)))
242 (save-excursion 242 (let* ((ignore-final-newline
243 (set-buffer (window-buffer window)) 243 ;; If buffer ends with a newline, ignore it when counting height
244 (let* ((w (selected-window)) ;save-window-excursion can't win 244 ;; unless point is after it.
245 (buffer-file-name buffer-file-name) 245 (and (not (eobp))
246 (p (point)) 246 (eq ?\n (char-after (1- (point-max))))))
247 (n 0) 247 (params (frame-parameters (window-frame window)))
248 (ignore-final-newline 248 (mini (cdr (assq 'minibuffer params)))
249 ;; If buffer ends with a newline, ignore it when counting height 249 (edges (window-edges (selected-window))))
250 ;; unless point is after it. 250 (if (and (< 1 (save-selected-window
251 (and (not (eobp)) 251 (select-window window)
252 (eq ?\n (char-after (1- (point-max)))))) 252 (count-windows)))
253 (buffer-read-only nil) 253 (= (window-width window) (frame-width (window-frame window)))
254 (modified (buffer-modified-p)) 254 (pos-visible-in-window-p (point-min) window)
255 (buffer (current-buffer)) 255 (not (eq mini 'only))
256 (params (frame-parameters (window-frame window))) 256 (or (not mini)
257 (mini (cdr (assq 'minibuffer params))) 257 (< (nth 3 edges)
258 (edges (window-edges (selected-window)))) 258 (nth 1 (window-edges mini)))
259 (if (and (< 1 (let ((frame (selected-frame))) 259 (> (nth 1 edges)
260 (select-frame (window-frame window)) 260 (cdr (assq 'menu-bar-lines params)))))
261 (unwind-protect 261 (save-selected-window
262 (count-windows) 262 (select-window window)
263 (select-frame frame)))) 263 (let (result height)
264 (= (window-width window) (frame-width (window-frame window))) 264 (save-excursion
265 (pos-visible-in-window-p (point-min) window) 265 (set-buffer (window-buffer window))
266 (not (eq mini 'only)) 266 (goto-char (point-min))
267 (or (not mini) 267 (setq result
268 (< (nth 3 edges) 268 (compute-motion (point-min) '(0 . 0)
269 (nth 1 (window-edges mini))) 269 (- (point-max)
270 (> (nth 1 edges) 270 (if ignore-final-newline 1 0))
271 (cdr (assq 'menu-bar-lines params))))) 271 (cons 0 (window-height))
272 (unwind-protect 272 (window-width) nil
273 (progn 273 window))
274 (select-window (or window w)) 274 ;; Get number of screen lines that the text needs.
275 (goto-char (point-min)) 275 (setq text-height (+ 1 (nth 2 result)))
276 (while (pos-visible-in-window-p 276 ;; Shrink down to that, or as far as we can go.
277 (- (point-max) 277 (if (> (window-height) (1+ text-height))
278 (if ignore-final-newline 1 0))) 278 (shrink-window (- (window-height)
279 ;; defeat file locking... don't try this at home, kids! 279 (max (1+ text-height) window-min-height))))))))))
280 (setq buffer-file-name nil)
281 (insert ?\n) (setq n (1+ n)))
282 (if (> n 0)
283 (shrink-window (min (1- n)
284 (- (window-height)
285 window-min-height)))))
286 (delete-region (point-min) (point))
287 (set-buffer-modified-p modified)
288 (goto-char p)
289 (select-window w)
290 ;; Make sure we unbind buffer-read-only
291 ;; with the proper current buffer.
292 (set-buffer buffer))))))
293 280
294(defun kill-buffer-and-window () 281(defun kill-buffer-and-window ()
295 "Kill the current buffer and delete the selected window." 282 "Kill the current buffer and delete the selected window."