aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-11-22 17:26:33 +0000
committerRichard M. Stallman1998-11-22 17:26:33 +0000
commit3b134005bb34dfd1c0dd01f1d0cbaa5688fd4fbc (patch)
tree9fa1e43edb72a73b03f2610acff31384c47589e7
parent48ce3c223194833596a0d50cc8122d979d61d073 (diff)
downloademacs-3b134005bb34dfd1c0dd01f1d0cbaa5688fd4fbc.tar.gz
emacs-3b134005bb34dfd1c0dd01f1d0cbaa5688fd4fbc.zip
(window-buffer-height): New function, split from
shrink-window-if-larger-than-buffer. (shrink-window-if-larger-than-buffer): Use window-buffer-height.
-rw-r--r--lisp/window.el67
1 files changed, 32 insertions, 35 deletions
diff --git a/lisp/window.el b/lisp/window.el
index c18dcc41acc..cd043e0d47e 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -237,6 +237,23 @@ to the window's right, if any. No arg means split equally."
237 (interactive "p") 237 (interactive "p")
238 (shrink-window arg t)) 238 (shrink-window arg t))
239 239
240(defun window-buffer-height (window)
241 "Return the height (in screen lines) of the buffer that WINDOW is displaying."
242 (save-excursion
243 (set-buffer (window-buffer window))
244 (goto-char (point-min))
245 (let ((ignore-final-newline
246 ;; If buffer ends with a newline, ignore it when counting height
247 ;; unless point is after it.
248 (and (not (eobp)) (eq ?\n (char-after (1- (point-max)))))))
249 (+ 1 (nth 2 (compute-motion (point-min)
250 '(0 . 0)
251 (- (point-max) (if ignore-final-newline 1 0))
252 (cons 0 100000000)
253 (window-width window)
254 nil
255 window))))))
256
240(defun shrink-window-if-larger-than-buffer (&optional window) 257(defun shrink-window-if-larger-than-buffer (&optional window)
241 "Shrink the WINDOW to be as small as possible to display its contents. 258 "Shrink the WINDOW to be as small as possible to display its contents.
242Do not shrink to less than `window-min-height' lines. 259Do not shrink to less than `window-min-height' lines.
@@ -249,41 +266,21 @@ or if the window is the only window of its frame."
249 (if window 266 (if window
250 (select-window window) 267 (select-window window)
251 (setq window (selected-window))) 268 (setq window (selected-window)))
252 (save-excursion 269 (let* ((params (frame-parameters))
253 (set-buffer (window-buffer window)) 270 (mini (cdr (assq 'minibuffer params)))
254 (goto-char (point-min)) 271 (edges (window-edges)))
255 (let* ((ignore-final-newline 272 (if (and (< 1 (count-windows))
256 ;; If buffer ends with a newline, ignore it when counting height 273 (= (window-width) (frame-width))
257 ;; unless point is after it. 274 (pos-visible-in-window-p (point-min) window)
258 (and (not (eobp)) 275 (not (eq mini 'only))
259 (eq ?\n (char-after (1- (point-max)))))) 276 (or (not mini)
260 (params (frame-parameters)) 277 (< (nth 3 edges) (nth 1 (window-edges mini)))
261 (mini (cdr (assq 'minibuffer params))) 278 (> (nth 1 edges) (cdr (assq 'menu-bar-lines params)))))
262 (edges (window-edges)) 279 (let ((text-height (window-buffer-height window))
263 text-height) 280 (window-height (window-height)))
264 (if (and (< 1 (count-windows)) 281 (when (> window-height (1+ text-height))
265 (= (window-width) (frame-width)) 282 (shrink-window
266 (pos-visible-in-window-p (point-min) window) 283 (- window-height (max (1+ text-height) window-min-height)))))))))
267 (not (eq mini 'only))
268 (or (not mini)
269 (< (nth 3 edges)
270 (nth 1 (window-edges mini)))
271 (> (nth 1 edges)
272 (cdr (assq 'menu-bar-lines params)))))
273 (let (result height)
274 (setq result
275 (compute-motion (point-min) '(0 . 0)
276 (- (point-max)
277 (if ignore-final-newline 1 0))
278 (cons 0 (window-height))
279 (window-width) nil
280 window))
281 ;; Get number of screen lines that the text needs.
282 (setq text-height (+ 1 (nth 2 result)))
283 ;; Shrink down to that, or as far as we can go.
284 (if (> (window-height) (1+ text-height))
285 (shrink-window (- (window-height)
286 (max (1+ text-height) window-min-height))))))))))
287 284
288(defun kill-buffer-and-window () 285(defun kill-buffer-and-window ()
289 "Kill the current buffer and delete the selected window." 286 "Kill the current buffer and delete the selected window."