bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

balance-windows doesn't


From: Per Starback
Subject: balance-windows doesn't
Date: Sat, 8 Dec 2001 00:39:30 +0100

GNU Emacs 21.1:

With a 24-line terminal do

     $ emacs -nw -q
     (setq window-min-height 2) LFD
     C-x 2 C-x 2 C-x 2 C-x +

The (window-height)s for the four windows are now 6, 2, 9, 6, which
isn't very balanced.  I expected it to be 6, 6, 6, 5, or any
permutation of that.

If I repeat C-x + it looks fine.

The problem is that when balance-windows uses enlarge-window to fix
the window heights that may change the heights of windows that
previously have been fixed so that they aren't good anymore.

It's not evident how to fix this best, but I have a suggestion, namely
to simply repeat the balancing until we get a fix point or a loop.  That
requires only a few iterations in practice and yields good (although
perhaps not always perfect) solutions.

*** window.el.~1.79~    Fri Dec  7 23:07:03 2001
--- window.el   Sat Dec  8 00:23:25 2001
***************
*** 169,208 ****
      ;; Find all the different vpos's at which windows start,
      ;; then count them.  But ignore levels that differ by only 1.
      (save-window-excursion
!       (let (tops (prev-top -2))
!       (walk-windows (function (lambda (w)
!                                 (setq tops (cons (nth 1 (window-edges w))
!                                                  tops))))
                      'nomini)
        (setq tops (sort tops '<))
        (while tops
          (if (> (car tops) (1+ prev-top))
              (setq prev-top (car tops)
                    count (1+ count)))
!         (setq levels (cons (cons (car tops) count) levels))
          (setq tops (cdr tops)))
        (setq count (1+ count))))
      ;; Subdivide the frame into that many vertical levels.
      (setq size (/ (- (frame-height) mbl) count))
!     (walk-windows (function
!                  (lambda (w)
!                    (select-window w)
!                    (let ((newtop (cdr (assq (nth 1 (window-edges))
!                                             levels)))
!                          (newbot (or (cdr (assq (+ (window-height)
!                                                    (nth 1 (window-edges)))
!                                                 levels))
!                                      count)))
!                      (setq newsizes
!                            (cons (cons w (* size (- newbot newtop)))
!                                  newsizes)))))
                  'nomini)
!     (walk-windows (function (lambda (w)
!                             (select-window w)
!                             (let ((newsize (cdr (assq w newsizes))))
!                               (enlarge-window (- newsize
!                                                  (window-height))))))
!                 'nomini)))
  
  ;;; I think this should be the default; I think people will prefer it--rms.
  (defcustom split-window-keep-point t
--- 169,217 ----
      ;; Find all the different vpos's at which windows start,
      ;; then count them.  But ignore levels that differ by only 1.
      (save-window-excursion
!       (let ((tops '())
!           (prev-top -2))
!       (walk-windows (lambda (w) (push (nth 1 (window-edges w))
!                                       tops))
                      'nomini)
        (setq tops (sort tops '<))
        (while tops
          (if (> (car tops) (1+ prev-top))
              (setq prev-top (car tops)
                    count (1+ count)))
!         (push (cons (car tops) count) levels)
          (setq tops (cdr tops)))
        (setq count (1+ count))))
      ;; Subdivide the frame into that many vertical levels.
      (setq size (/ (- (frame-height) mbl) count))
!     (walk-windows (lambda (w)
!                   (select-window w)
!                   (let ((newtop (cdr (assq (nth 1 (window-edges))
!                                            levels)))
!                         (newbot (or (cdr (assq (+ (window-height)
!                                                   (nth 1 (window-edges)))
!                                                levels))
!                                     count)))
!                     (push (cons w (* size (- newbot newtop)))
!                           newsizes)))
                  'nomini)
!     ;; We use enlarge-window to fix the sizes of the windows, but that
!     ;; may shrink previously enlarged windows so the result isn't very
!     ;; balanced. Therefore repeat this as long as we get new window
!     ;; configurations. There are no guarantees that the final result
!     ;; will be optimal, but it will probably not be far off.
!     (let ((used-configurations '()))
!       (while (not (member (current-window-configuration) used-configurations))
!       (push (current-window-configuration) used-configurations)
!       (walk-windows (lambda (w)
!                       (select-window w)
!                       (let ((newsize (cdr (assq w newsizes))))
!                         (enlarge-window (- newsize
!                                            (window-height)))))
!                     'nomini)))))
! 
! (defun windows-balanced-p ()
!   nil)
  
  ;;; I think this should be the default; I think people will prefer it--rms.
  (defcustom split-window-keep-point t



reply via email to

[Prev in Thread] Current Thread [Next in Thread]