[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: shrink-window-if-larger-than-buffer in VC-diff
From: |
Chong Yidong |
Subject: |
Re: shrink-window-if-larger-than-buffer in VC-diff |
Date: |
Wed, 18 Aug 2010 17:53:09 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Juanma Barranquero <address@hidden> writes:
>> Maybe we should change `pop-to-buffer' so that it accepts
>> an option to both shrink *and* grow windows. Then people who want their
>> windows to resize automagically can use this option, and have it work
>> more reliably than it does now. (The default should be to avoid
>> resizing at all.)
>
> I'm OK with that.
Here's a possible implementation, which replaces even-window-heights
with a new option `resize-windows-for-display'. The value `fit' says to
resize the displayed/popped windows. What do you think?
=== modified file 'lisp/window.el'
*** lisp/window.el 2010-06-07 18:28:02 +0000
--- lisp/window.el 2010-08-18 21:46:44 +0000
***************
*** 989,1025 ****
))
frame))))
! (defcustom even-window-heights t
! "If non-nil `display-buffer' will try to even window heights.
! Otherwise `display-buffer' will leave the window configuration
! alone. Heights are evened only when `display-buffer' chooses a
! window that appears above or below the selected window."
! :type 'boolean
! :group 'windows)
! (defun window--even-window-heights (window)
! "Even heights of WINDOW and selected window.
! Do this only if these windows are vertically adjacent to each
! other, `even-window-heights' is non-nil, and the selected window
! is higher than WINDOW."
! (when (and even-window-heights
! (not (eq window (selected-window)))
! ;; Don't resize minibuffer windows.
! (not (window-minibuffer-p (selected-window)))
! (> (window-height (selected-window)) (window-height window))
! (eq (window-frame window) (window-frame (selected-window)))
! (let ((sel-edges (window-edges (selected-window)))
! (win-edges (window-edges window)))
! (and (= (nth 0 sel-edges) (nth 0 win-edges))
! (= (nth 2 sel-edges) (nth 2 win-edges))
! (or (= (nth 1 sel-edges) (nth 3 win-edges))
! (= (nth 3 sel-edges) (nth 1 win-edges))))))
! (let ((window-min-height 1))
! ;; Don't throw an error if we can't even window heights for
! ;; whatever reason.
! (condition-case nil
! (enlarge-window (/ (- (window-height window) (window-height)) 2))
! (error nil)))))
(defun window--display-buffer-1 (window)
"Raise the frame containing WINDOW.
--- 989,1030 ----
))
frame))))
! (defcustom resize-windows-for-display t
! "Whether `display-buffer' should resize windows.
! If nil, leave the window configuration alone.
! If `fit', try to shrink the chosen window if its buffer does not
! need so many lines; otherwise, try to even the window heights.
! For any other non-nil value, try to even the window heights if
! the chosen window appears above or below the selected window."
! :type '(choice (const :tag "Equalize window heights" t)
! (const :tag "Best fit" 'fit)
! (const :tag "No resize" nil))
! :group 'windows
! :version "24.1")
! (define-obsolete-variable-alias 'even-window-heights
'resize-windows-for-display)
!
! (defun window--adjust-window-heights (window)
! "Adjust height of WINDOW according to `resize-windows-for-display'."
! ;; Try shrinking window if `resize-windows-for-display' is `fit'.
! (and resize-windows-for-display
! (not (and (eq resize-windows-for-display 'fit)
! (shrink-window-if-larger-than-buffer window)))
! (not (eq window (selected-window)))
! (not (window-minibuffer-p (selected-window)))
! (eq (window-frame window) (window-frame (selected-window)))
! (let ((sel-edges (window-edges (selected-window)))
! (win-edges (window-edges window)))
! (and (= (nth 0 sel-edges) (nth 0 win-edges))
! (= (nth 2 sel-edges) (nth 2 win-edges))
! (or (= (nth 1 sel-edges) (nth 3 win-edges))
! (= (nth 3 sel-edges) (nth 1 win-edges)))))
! (let ((window-min-height 1))
! ;; Don't throw an error if we can't even window heights for
! ;; whatever reason.
! (condition-case nil
! (enlarge-window (/ (- (window-height window) (window-height)) 2))
! (error nil)))))
(defun window--display-buffer-1 (window)
"Raise the frame containing WINDOW.
***************
*** 1036,1047 ****
(raise-frame frame))
window))
! (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.
Return WINDOW."
(when (and (buffer-live-p buffer) (window-live-p window))
(set-window-buffer window buffer)
(when dedicated
(set-window-dedicated-p window dedicated))
(window--display-buffer-1 window)))
--- 1041,1056 ----
(raise-frame frame))
window))
! (defun window--display-buffer-2 (buffer window &optional dedicated
adjust-size)
"Display BUFFER in WINDOW and make its frame visible.
! If DEDICATED is non-nil, set `window-dedicated-p'.
! If ADJUST-SIZE is non-nil, resize WINDOW according to
! `resize-windows-for-display'.
Return WINDOW."
(when (and (buffer-live-p buffer) (window-live-p window))
(set-window-buffer window buffer)
+ (when adjust-size
+ (window--adjust-window-heights window))
(when dedicated
(set-window-dedicated-p window dedicated))
(window--display-buffer-1 window)))
***************
*** 1160,1166 ****
(window--try-to-split-window
(get-lru-window frame-to-use t)))))
(window--display-buffer-2 buffer window-to-use
! display-buffer-mark-dedicated))
((let ((window-to-undedicate
;; When NOT-THIS-WINDOW is non-nil, temporarily dedicate
;; the selected window to its buffer, to avoid that some of
--- 1169,1175 ----
(window--try-to-split-window
(get-lru-window frame-to-use t)))))
(window--display-buffer-2 buffer window-to-use
! display-buffer-mark-dedicated t))
((let ((window-to-undedicate
;; When NOT-THIS-WINDOW is non-nil, temporarily dedicate
;; the selected window to its buffer, to avoid that some of
***************
*** 1186,1193 ****
(when (window-live-p window-to-undedicate)
;; Restore dedicated status of selected window.
(set-window-dedicated-p window-to-undedicate nil))))
! (window--even-window-heights window-to-use)
! (window--display-buffer-2 buffer window-to-use)))))
(defun pop-to-buffer (buffer-or-name &optional other-window norecord)
"Select buffer BUFFER-OR-NAME in some window, preferably a different one.
--- 1195,1201 ----
(when (window-live-p window-to-undedicate)
;; Restore dedicated status of selected window.
(set-window-dedicated-p window-to-undedicate nil))))
! (window--display-buffer-2 buffer window-to-use nil t)))))
(defun pop-to-buffer (buffer-or-name &optional other-window norecord)
"Select buffer BUFFER-OR-NAME in some window, preferably a different one.
*** lisp/vc/vc.el 2010-07-16 15:42:15 +0000
--- lisp/vc/vc.el 2010-08-18 21:50:15 +0000
***************
*** 1511,1517 ****
(message "%s" (cdr messages))))
(goto-char (point-min))
(when window
! (shrink-window-if-larger-than-buffer window)))
(when (and messages (not emptyp))
(message "%sdone" (car messages))))))
--- 1511,1517 ----
(message "%s" (cdr messages))))
(goto-char (point-min))
(when window
! (window--adjust-window-heights window)))
(when (and messages (not emptyp))
(message "%sdone" (car messages))))))
***************
*** 1583,1589 ****
(vc-exec-after `(vc-diff-finish ,(current-buffer) ',(when verbose
messages)))
;; Display the buffer, but at the end because it can change point.
! (pop-to-buffer (current-buffer))
;; In the async case, we return t even if there are no differences
;; because we don't know that yet.
t)))
--- 1583,1590 ----
(vc-exec-after `(vc-diff-finish ,(current-buffer) ',(when verbose
messages)))
;; Display the buffer, but at the end because it can change point.
! (let ((resize-windows-for-display nil))
! (pop-to-buffer (current-buffer)))
;; In the async case, we return t even if there are no differences
;; because we don't know that yet.
t)))
- annoyances [Was: shrink-window-if-larger-than-buffer in VC-diff], (continued)
Re: shrink-window-if-larger-than-buffer in VC-diff, Juanma Barranquero, 2010/08/15