Mercurial > emacs
comparison lisp/window.el @ 32689:9f29610841ca
(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.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 20 Oct 2000 15:16:46 +0000 |
parents | 303175f14c7d |
children | 5a4f1fbd4ed7 |
comparison
equal
deleted
inserted
replaced
32688:40878cdc6a2a | 32689:9f29610841ca |
---|---|
284 | 284 |
285 ;; List of face attributes that might change a face's height | 285 ;; List of face attributes that might change a face's height |
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 | |
293 FACE is the face used to display the mode-line; it defaults to `mode-line'. | |
292 | 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 |
296 returned, otherwise 0. | 298 returned, otherwise 0. |
312 ;; could make it bigger than a default text line, and return a | 314 ;; could make it bigger than a default text line, and return a |
313 ;; fudge factor of 1 if so. | 315 ;; fudge factor of 1 if so. |
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." |
325 (interactive "p") | 370 (interactive "p") |
326 (enlarge-window arg t)) | 371 (enlarge-window arg t)) |
402 (pos-visible-in-window-p (point-min) window) | 447 (pos-visible-in-window-p (point-min) window) |
403 (not (eq mini 'only)) | 448 (not (eq mini 'only)) |
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." |
424 (interactive) | 472 (interactive) |
425 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name))) | 473 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name))) |