emacs-devel
[Top][All Lists]
Advanced

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

Resizing windows after display-buffer


From: Chong Yidong
Subject: Resizing windows after display-buffer
Date: Sun, 24 Apr 2011 19:45:16 -0400

Not long ago, we discussed generalizing temp-buffer-resize-mode so that
it isn't just for Help buffers.  I propose doing this not with a minor
mode, but by adding a defcustom, display-buffer-fit-window-to-buffer.
See attached patch; window--display-buffer-2 (a subroutine of
display-buffer) will check this and call fit-window-to-buffer.

This should make temp-buffer-resize-mode unnecessary.  It will also
hopefully allow us to eliminate most calls to fit-window-to-buffer in
the Lisp tree (which are completely unregulated AFAICT), instead putting
the decision to fit displayed windows into one customizable location.

Thoughts/suggestions?


*** lisp/window.el      2011-04-19 13:44:55 +0000
--- lisp/window.el      2011-04-24 23:35:43 +0000
***************
*** 1038,1043 ****
--- 1038,1059 ----
        (raise-frame frame))
      window))
  
+ (defcustom display-buffer-fit-window-to-buffer nil
+   "Whether `display-buffer' should resize windows.
+ If the value is nil, no resizing is done.
+ 
+ If the value is non-nil, it should be a cons cell (MIN . MAX).
+ Any time `display-buffer' displays a buffer in another window, it
+ calls `fit-window-to-buffer', using MIN and MAX as the minimum
+ and maximum window heights.  Integers specify numbers of lines,
+ while floating point numbers specify fractions of the frame
+ height.
+ 
+ This variable has no effect when `display-buffer-function' is
+ non-nil, unless the specified function handles it explicitly."
+   :type '(choice (const nil) cons)
+   :group 'display)
+ 
  (defun window--display-buffer-2 (buffer window &optional dedicated)
    "Display BUFFER in WINDOW and make its frame visible.
  Set `window-dedicated-p' to DEDICATED if non-nil.
***************
*** 1046,1052 ****
      (set-window-buffer window buffer)
      (when dedicated
        (set-window-dedicated-p window dedicated))
!     (window--display-buffer-1 window)))
  
  (defvar display-buffer-mark-dedicated nil
    "If non-nil, `display-buffer' marks the windows it creates as dedicated.
--- 1062,1075 ----
      (set-window-buffer window buffer)
      (when dedicated
        (set-window-dedicated-p window dedicated))
!     (prog1 (window--display-buffer-1 window)
!       (when (consp display-buffer-fit-window-to-buffer)
!       (let ((min (car display-buffer-fit-window-to-buffer))
!             (max (cdr display-buffer-fit-window-to-buffer))
!             (frame-height (frame-height (window-frame window))))
!         (if (floatp min) (setq min (round (* min frame-height))))
!         (if (floatp max) (setq max (round (* max frame-height))))
!         (fit-window-to-buffer window max min))))))
  
  (defvar display-buffer-mark-dedicated nil
    "If non-nil, `display-buffer' marks the windows it creates as dedicated.



reply via email to

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