diff options
| author | Miles Bader | 2000-10-20 15:16:46 +0000 |
|---|---|---|
| committer | Miles Bader | 2000-10-20 15:16:46 +0000 |
| commit | 361691dc0d63b082e3eb2590206ac3fa93ed0486 (patch) | |
| tree | 74e2b1b82e1953a637b254512650ff92b17d6210 | |
| parent | ea456eb4e4549655bb67660b00ec4a574ec82209 (diff) | |
| download | emacs-361691dc0d63b082e3eb2590206ac3fa93ed0486.tar.gz emacs-361691dc0d63b082e3eb2590206ac3fa93ed0486.zip | |
(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.
| -rw-r--r-- | lisp/window.el | 64 |
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." | |||
| 286 | (defconst height-affecting-face-attributes | 286 | (defconst height-affecting-face-attributes |
| 287 | '(:family :height :box :font :inherit)) | 287 | '(:family :height :box :font :inherit)) |
| 288 | 288 | ||
| 289 | (defsubst mode-line-window-height-fudge () | 289 | (defsubst mode-line-window-height-fudge (&optional face) |
| 290 | "Return a fudge factor to compensate for the extra height of graphic mode-lines. | 290 | "Return a fudge factor to compensate for the extra height of graphic mode-lines. |
| 291 | On a non-graphic display, return 0. | 291 | On a non-graphic display, return 0. |
| 292 | 292 | ||
| 293 | FACE is the face used to display the mode-line; it defaults to `mode-line'. | ||
| 294 | |||
| 293 | If the variable `mode-line-window-height-fudge' has a non-nil value, it | 295 | If the variable `mode-line-window-height-fudge' has a non-nil value, it |
| 294 | is returned. Otherwise, the `mode-line' face is checked to see if it | 296 | is returned. Otherwise, the `mode-line' face is checked to see if it |
| 295 | contains any attributes that might affect its height; if it does, 1 is | 297 | contains any attributes that might affect its height; if it does, 1 is |
| @@ -314,11 +316,54 @@ This is a kluge." | |||
| 314 | (let ((attrs height-affecting-face-attributes) | 316 | (let ((attrs height-affecting-face-attributes) |
| 315 | (fudge 0)) | 317 | (fudge 0)) |
| 316 | (while attrs | 318 | (while attrs |
| 317 | (let ((val (face-attribute 'mode-line (pop attrs)))) | 319 | (let ((val (face-attribute (or face 'mode-line) (pop attrs)))) |
| 318 | (unless (or (null val) (eq val 'unspecified)) | 320 | (unless (or (null val) (eq val 'unspecified)) |
| 319 | (setq fudge 1 attrs nil)))) | 321 | (setq fudge 1 attrs nil)))) |
| 320 | fudge)) | 322 | fudge)) |
| 321 | 0)) | 323 | 0)) |
| 324 | |||
| 325 | |||
| 326 | ;;; These functions should eventually be replaced with versions that | ||
| 327 | ;;; really do the job (instead of using the kludgey mode-line face | ||
| 328 | ;;; hacking junk). | ||
| 329 | |||
| 330 | (defun window-text-height (&optional window) | ||
| 331 | "Return the height in lines of the text display area of WINDOW. | ||
| 332 | This doesn't include the mode-line (or header-line if any) or any | ||
| 333 | partial-height lines in the text display area. | ||
| 334 | |||
| 335 | Note that the current implementation of this function may sometimes | ||
| 336 | return an inaccurate value, but attempts to be conservative, by | ||
| 337 | returning fewer lines than actually exist in the case where the real | ||
| 338 | value cannot be determined." | ||
| 339 | (with-current-buffer (window-buffer window) | ||
| 340 | (- (window-height window) | ||
| 341 | (if mode-line-format | ||
| 342 | (1+ (mode-line-window-height-fudge)) | ||
| 343 | 0) | ||
| 344 | (if header-line-format | ||
| 345 | (1+ (mode-line-window-height-fudge 'header-line)) | ||
| 346 | 0)))) | ||
| 347 | |||
| 348 | (defun set-window-text-height (window height) | ||
| 349 | "Sets the height in lines of the text display area of WINDOW to HEIGHT. | ||
| 350 | This doesn't include the mode-line (or header-line if any) or any | ||
| 351 | partial-height lines in the text display area. | ||
| 352 | |||
| 353 | If WINDOW is nil, the selected window is used. | ||
| 354 | If HEIGHT is less than `window-min-height', then WINDOW is deleted. | ||
| 355 | |||
| 356 | Note that the current implementation of this function cannot always set | ||
| 357 | the height exactly, but attempts to be conservative, by allocating more | ||
| 358 | lines than are actually needed in the case where some error may be present." | ||
| 359 | (let ((delta (- height (window-text-height window)))) | ||
| 360 | (unless (zerop delta) | ||
| 361 | (if (and window (not (eq window (selected-window)))) | ||
| 362 | (save-selected-window | ||
| 363 | (select-window window) | ||
| 364 | (enlarge-window delta)) | ||
| 365 | (enlarge-window delta))))) | ||
| 366 | |||
| 322 | 367 | ||
| 323 | (defun enlarge-window-horizontally (arg) | 368 | (defun enlarge-window-horizontally (arg) |
| 324 | "Make current window ARG columns wider." | 369 | "Make current window ARG columns wider." |
| @@ -404,20 +449,23 @@ or if the window is the only window of its frame." | |||
| 404 | (or (not mini) | 449 | (or (not mini) |
| 405 | (< (nth 3 edges) (nth 1 (window-edges mini))) | 450 | (< (nth 3 edges) (nth 1 (window-edges mini))) |
| 406 | (> (nth 1 edges) (frame-parameter nil 'menu-bar-lines)))) | 451 | (> (nth 1 edges) (frame-parameter nil 'menu-bar-lines)))) |
| 452 | |||
| 407 | ;; `count-screen-lines' always works on the current buffer, so | 453 | ;; `count-screen-lines' always works on the current buffer, so |
| 408 | ;; make sure it is the buffer displayed by WINDOW. | 454 | ;; make sure it is the buffer displayed by WINDOW. |
| 409 | (let ((text-height | 455 | (let ((text-height |
| 410 | (+ (with-current-buffer (window-buffer window) | 456 | (with-current-buffer (window-buffer window) |
| 411 | (count-screen-lines)) | 457 | (count-screen-lines))) |
| 412 | (mode-line-window-height-fudge))) | 458 | (window-height |
| 413 | (window-height (window-height))) | 459 | (window-text-height))) |
| 460 | |||
| 414 | ;; Don't try to redisplay with the cursor at the end | 461 | ;; Don't try to redisplay with the cursor at the end |
| 415 | ;; on its own line--that would force a scroll and spoil things. | 462 | ;; on its own line--that would force a scroll and spoil things. |
| 416 | (when (and (eobp) (bolp) (not (bobp))) | 463 | (when (and (eobp) (bolp) (not (bobp))) |
| 417 | (forward-char -1)) | 464 | (forward-char -1)) |
| 418 | (when (> window-height (1+ text-height)) | 465 | |
| 466 | (when (> window-height text-height) | ||
| 419 | (shrink-window | 467 | (shrink-window |
| 420 | (- window-height (max (1+ text-height) window-min-height))))))))) | 468 | (- window-height (max text-height window-min-height))))))))) |
| 421 | 469 | ||
| 422 | (defun kill-buffer-and-window () | 470 | (defun kill-buffer-and-window () |
| 423 | "Kill the current buffer and delete the selected window." | 471 | "Kill the current buffer and delete the selected window." |