[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
shrink-window-if-larger-than-buffer
From: |
John J Foerch |
Subject: |
shrink-window-if-larger-than-buffer |
Date: |
Fri, 15 Feb 2008 13:11:05 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux) |
Hello,
I changed shrink-window-if-larger-than-buffer to operate on
(next-window) when it is called interactively with the universal
argument. I'm posting in case anyone else thinks this is a useful
change.
(defun shrink-window-if-larger-than-buffer (&optional window)
"Shrink the WINDOW to be as small as possible to display its contents.
If WINDOW is omitted or nil, it defaults to the selected window.
Do not shrink to less than `window-min-height' lines.
Do nothing if the buffer contains more lines than the present window height,
or if some of the window's contents are scrolled out of view,
or if shrinking this window would also shrink another window,
or if the window is the only window of its frame."
(interactive "P")
(when (null window)
(setq window (selected-window)))
(when (consp window)
(setq window (next-window)))
(let* ((frame (window-frame window))
(mini (frame-parameter frame 'minibuffer))
(edges (window-edges window)))
(if (and (not (eq window (frame-root-window frame)))
(window-safely-shrinkable-p)
(pos-visible-in-window-p (point-min) window)
(not (eq mini 'only))
(or (not mini)
(let ((mini-window (minibuffer-window frame)))
(or (null mini-window)
(not (eq frame (window-frame mini-window)))
(< (nth 3 edges)
(nth 1 (window-edges mini-window)))
(> (nth 1 edges)
(frame-parameter frame 'menu-bar-lines))))))
(fit-window-to-buffer window (window-height window)))))
Thank you,
John Foerch
- shrink-window-if-larger-than-buffer,
John J Foerch <=