summaryrefslogtreecommitdiff
path: root/lisp/window.el
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>2000-10-20 15:16:46 +0000
committerMiles Bader <miles@gnu.org>2000-10-20 15:16:46 +0000
commit361691dc0d63b082e3eb2590206ac3fa93ed0486 (patch)
tree74e2b1b82e1953a637b254512650ff92b17d6210 /lisp/window.el
parentea456eb4e4549655bb67660b00ec4a574ec82209 (diff)
downloademacs-361691dc0d63b082e3eb2590206ac3fa93ed0486.tar.gz
(window-text-height, set-window-text-height): New functions.
(shrink-window-if-larger-than-buffer): Use `window-text-height' instead of `window-height' & `mode-line-window-height-fudge'. (mode-line-window-height-fudge): Add FACE parameter.
Diffstat (limited to 'lisp/window.el')
-rw-r--r--lisp/window.el64
1 files changed, 56 insertions, 8 deletions
diff --git a/lisp/window.el b/lisp/window.el
index e2d871c7033..9eb15684a85 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -286,10 +286,12 @@ This is a kluge."
(defconst height-affecting-face-attributes
'(:family :height :box :font :inherit))
-(defsubst mode-line-window-height-fudge ()
+(defsubst mode-line-window-height-fudge (&optional face)
"Return a fudge factor to compensate for the extra height of graphic mode-lines.
On a non-graphic display, return 0.
+FACE is the face used to display the mode-line; it defaults to `mode-line'.
+
If the variable `mode-line-window-height-fudge' has a non-nil value, it
is returned. Otherwise, the `mode-line' face is checked to see if it
contains any attributes that might affect its height; if it does, 1 is
@@ -314,11 +316,54 @@ This is a kluge."
(let ((attrs height-affecting-face-attributes)
(fudge 0))
(while attrs
- (let ((val (face-attribute 'mode-line (pop attrs))))
+ (let ((val (face-attribute (or face 'mode-line) (pop attrs))))
(unless (or (null val) (eq val 'unspecified))
(setq fudge 1 attrs nil))))
fudge))
0))
+
+
+;;; These functions should eventually be replaced with versions that
+;;; really do the job (instead of using the kludgey mode-line face
+;;; hacking junk).
+
+(defun window-text-height (&optional window)
+ "Return the height in lines of the text display area of WINDOW.
+This doesn't include the mode-line (or header-line if any) or any
+partial-height lines in the text display area.
+
+Note that the current implementation of this function may sometimes
+return an inaccurate value, but attempts to be conservative, by
+returning fewer lines than actually exist in the case where the real
+value cannot be determined."
+ (with-current-buffer (window-buffer window)
+ (- (window-height window)
+ (if mode-line-format
+ (1+ (mode-line-window-height-fudge))
+ 0)
+ (if header-line-format
+ (1+ (mode-line-window-height-fudge 'header-line))
+ 0))))
+
+(defun set-window-text-height (window height)
+ "Sets the height in lines of the text display area of WINDOW to HEIGHT.
+This doesn't include the mode-line (or header-line if any) or any
+partial-height lines in the text display area.
+
+If WINDOW is nil, the selected window is used.
+If HEIGHT is less than `window-min-height', then WINDOW is deleted.
+
+Note that the current implementation of this function cannot always set
+the height exactly, but attempts to be conservative, by allocating more
+lines than are actually needed in the case where some error may be present."
+ (let ((delta (- height (window-text-height window))))
+ (unless (zerop delta)
+ (if (and window (not (eq window (selected-window))))
+ (save-selected-window
+ (select-window window)
+ (enlarge-window delta))
+ (enlarge-window delta)))))
+
(defun enlarge-window-horizontally (arg)
"Make current window ARG columns wider."
@@ -404,20 +449,23 @@ or if the window is the only window of its frame."
(or (not mini)
(< (nth 3 edges) (nth 1 (window-edges mini)))
(> (nth 1 edges) (frame-parameter nil 'menu-bar-lines))))
+
;; `count-screen-lines' always works on the current buffer, so
;; make sure it is the buffer displayed by WINDOW.
(let ((text-height
- (+ (with-current-buffer (window-buffer window)
- (count-screen-lines))
- (mode-line-window-height-fudge)))
- (window-height (window-height)))
+ (with-current-buffer (window-buffer window)
+ (count-screen-lines)))
+ (window-height
+ (window-text-height)))
+
;; Don't try to redisplay with the cursor at the end
;; on its own line--that would force a scroll and spoil things.
(when (and (eobp) (bolp) (not (bobp)))
(forward-char -1))
- (when (> window-height (1+ text-height))
+
+ (when (> window-height text-height)
(shrink-window
- (- window-height (max (1+ text-height) window-min-height)))))))))
+ (- window-height (max text-height window-min-height)))))))))
(defun kill-buffer-and-window ()
"Kill the current buffer and delete the selected window."