comparison lisp/window.el @ 100374:216f983c6491

(fit-window-to-buffer): Return non-nil when height was orderly adjusted, nil otherwise.
author Martin Rudalics <rudalics@gmx.at>
date Fri, 12 Dec 2008 09:30:55 +0000
parents ecf3d51be3b3
children 096796d792df
comparison
equal deleted inserted replaced
100373:42c2c343946f 100374:216f983c6491
1292 (goto-char (point-min)) 1292 (goto-char (point-min))
1293 (1+ (vertical-motion (buffer-size) window)))))) 1293 (1+ (vertical-motion (buffer-size) window))))))
1294 1294
1295 (defun fit-window-to-buffer (&optional window max-height min-height) 1295 (defun fit-window-to-buffer (&optional window max-height min-height)
1296 "Adjust height of WINDOW to display its buffer's contents exactly. 1296 "Adjust height of WINDOW to display its buffer's contents exactly.
1297 WINDOW defaults to the selected window. Return nil. 1297 WINDOW defaults to the selected window.
1298 Optional argument MAX-HEIGHT specifies the maximum height of the 1298 Optional argument MAX-HEIGHT specifies the maximum height of the
1299 window and defaults to the maximum permissible height of a window 1299 window and defaults to the maximum permissible height of a window
1300 on WINDOW's frame. 1300 on WINDOW's frame.
1301 Optional argument MIN-HEIGHT specifies the minimum height of the 1301 Optional argument MIN-HEIGHT specifies the minimum height of the
1302 window and defaults to `window-min-height'. 1302 window and defaults to `window-min-height'.
1303 Both, MAX-HEIGHT and MIN-HEIGHT are specified in lines and 1303 Both, MAX-HEIGHT and MIN-HEIGHT are specified in lines and
1304 include the mode line and header line, if any. 1304 include the mode line and header line, if any.
1305 1305
1306 Return non-nil if height was orderly adjusted, nil otherwise.
1307
1306 Caution: This function can delete WINDOW and/or other windows 1308 Caution: This function can delete WINDOW and/or other windows
1307 when their height shrinks to less than MIN-HEIGHT." 1309 when their height shrinks to less than MIN-HEIGHT."
1308 (interactive) 1310 (interactive)
1309 ;; Do all the work in WINDOW and its buffer and restore the selected 1311 ;; Do all the work in WINDOW and its buffer and restore the selected
1310 ;; window and the current buffer when we're done. 1312 ;; window and the current buffer when we're done.
1311 (let ((old-buffer (current-buffer))) 1313 (let ((old-buffer (current-buffer))
1314 value)
1312 (with-selected-window (or window (setq window (selected-window))) 1315 (with-selected-window (or window (setq window (selected-window)))
1313 (set-buffer (window-buffer)) 1316 (set-buffer (window-buffer))
1314 ;; Use `condition-case' to handle any fixed-size windows and other 1317 ;; Use `condition-case' to handle any fixed-size windows and other
1315 ;; pitfalls nearby. 1318 ;; pitfalls nearby.
1316 (condition-case nil 1319 (condition-case nil
1382 (set-window-vscroll window 0) 1385 (set-window-vscroll window 0)
1383 (while (and (< desired-height max-height) 1386 (while (and (< desired-height max-height)
1384 (= desired-height (window-height)) 1387 (= desired-height (window-height))
1385 (not (pos-visible-in-window-p end))) 1388 (not (pos-visible-in-window-p end)))
1386 (enlarge-window 1) 1389 (enlarge-window 1)
1387 (setq desired-height (1+ desired-height)))))) 1390 (setq desired-height (1+ desired-height))))
1391 ;; Return non-nil only if nothing "bad" happened.
1392 (setq value t)))
1388 (error nil))) 1393 (error nil)))
1389 (when (buffer-live-p old-buffer) 1394 (when (buffer-live-p old-buffer)
1390 (set-buffer old-buffer)))) 1395 (set-buffer old-buffer))
1396 value))
1391 1397
1392 (defun window-safely-shrinkable-p (&optional window) 1398 (defun window-safely-shrinkable-p (&optional window)
1393 "Return t if WINDOW can be shrunk without shrinking other windows. 1399 "Return t if WINDOW can be shrunk without shrinking other windows.
1394 WINDOW defaults to the selected window." 1400 WINDOW defaults to the selected window."
1395 (with-selected-window (or window (selected-window)) 1401 (with-selected-window (or window (selected-window))