]> git.eshelyaron.com Git - emacs.git/commitdiff
(fit-window-to-buffer): Handle windows without mode-lines.
authorMiles Bader <miles@gnu.org>
Tue, 14 Nov 2000 12:58:47 +0000 (12:58 +0000)
committerMiles Bader <miles@gnu.org>
Tue, 14 Nov 2000 12:58:47 +0000 (12:58 +0000)
Handle header-lines.  Don't loop forever if we can't enlarge the
window anymore.  Simplify a bit.

lisp/ChangeLog
lisp/window.el

index 1a5102d5998c446ec82548cb81b6bd11cc43e872..ff1cd40d3bfad95ea2aa3a5571abfbf7e3db41b3 100644 (file)
@@ -1,3 +1,9 @@
+2000-11-14  Miles Bader  <miles@gnu.org>
+
+       * window.el (fit-window-to-buffer): Handle windows without mode-lines.
+       Handle header-lines.  Don't loop forever if we can't enlarge the
+       window anymore.  Simplify a bit.
+
 2000-11-14  Kenichi Handa  <handa@etl.go.jp>
 
        * window.el (fit-window-to-buffer): Don't check
@@ -57,6 +63,8 @@
        * textmodes/fill.el (skip-line-prefix): New function.
        (fill-region-as-paragraph, fill-region):  Return the fill-prefix.
        (fill-paragraph): Don't leave point inside the fill-prefix.
+       * textmodes/refill.el (refill-fill-paragraph-at): Don't leave
+       point inside the fill-prefix.
 
 2000-11-13  Miles Bader  <miles@lsi.nec.co.jp>
 
index 89dc9c6cbfe1278fe4be4f07dfe2599472e0538d..b6e5c1757d203ddcf2cd01b628dde50dc24816c3 100644 (file)
@@ -445,19 +445,27 @@ header-line."
   (when (null max-height)
     (setq max-height (frame-height (window-frame window))))
 
-  (let* ((window-height
+  (let* ((buf
+         ;; Buffer that is displayed in WINDOW
+         (window-buffer window))
+        (window-height
          ;; The current height of WINDOW
          (window-height window))
-        (text-height
+        (desired-height
          ;; The height necessary to show the buffer displayed by WINDOW
          ;; (`count-screen-lines' always works on the current buffer).
-         ;; We add 1 for mode-line.
-         (1+ (with-current-buffer (window-buffer window)
-               (count-screen-lines))))
+         (with-current-buffer buf
+           (+ (count-screen-lines)
+              ;; For non-minibuffers, count the mode-line, if any
+              (if (and (not (window-minibuffer-p window))
+                       mode-line-format)
+                  1 0)
+              ;; Count the header-line, if any
+              (if header-line-format 1 0))))
         (delta
          ;; Calculate how much the window height has to change to show
-         ;; text-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT.
-         (- (max (min text-height max-height)
+         ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT.
+         (- (max (min desired-height max-height)
                  (or min-height window-min-height))
             window-height))
         ;; We do our own height checking, so avoid any restrictions due to
@@ -466,31 +474,32 @@ header-line."
 
     ;; Don't try to redisplay with the cursor at the end
     ;; on its own line--that would force a scroll and spoil things.
-    (if (with-current-buffer (window-buffer window)
-         (and (eobp) (bolp) (not (bobp))))
-       (set-window-point window (1- (window-point window))))
+    (when (with-current-buffer buf
+           (and (eobp) (bolp) (not (bobp))))
+      (set-window-point window (1- (window-point window))))
 
-    (unless (zerop delta)
-      (if (eq window (selected-window))
-         (enlarge-window delta)
-       (save-selected-window
-         (select-window window)
-         (enlarge-window delta))))
-
-    ;; Check if the last line is surely fully visible.  If not,
-    ;; enlarge the window.
-    (let ((pos (with-current-buffer (window-buffer window)
-                (save-excursion
-                  (goto-char (point-max))
-                  (if (and (bolp) (not (bobp)))
-                      (1- (point))
-                    (point))))))
-      (set-window-vscroll window 0)
-      (save-selected-window
-       (select-window window)
-       (while (and (< (window-height window) max-height) 
-                   (not (pos-visible-in-window-p pos window t)))
-         (enlarge-window 1))))))
+    (save-selected-window
+      (select-window window)
+
+      ;; Adjust WINDOW to the nominally correct size (which may actually
+      ;; be slightly off because of variable height text, etc).
+      (unless (zerop delta)
+       (enlarge-window delta))
+
+      ;; Check if the last line is surely fully visible.  If not,
+      ;; enlarge the window.
+      (let ((end (with-current-buffer buf
+                  (save-excursion
+                    (goto-char (point-max))
+                    (if (and (bolp) (not (bobp)))
+                        (1- (point))
+                      (point))))))
+       (set-window-vscroll window 0)
+       (while (and (< desired-height max-height)
+                   (= desired-height (window-height window))
+                   (not (pos-visible-in-window-p end window t)))
+         (enlarge-window 1)
+         (setq desired-height (1+ desired-height)))))))
 
 (defun shrink-window-if-larger-than-buffer (&optional window)
   "Shrink the WINDOW to be as small as possible to display its contents.