unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@stupidchicken.com>
To: Juanma Barranquero <lekktu@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: shrink-window-if-larger-than-buffer in VC-diff
Date: Wed, 18 Aug 2010 17:53:09 -0400	[thread overview]
Message-ID: <87mxsjy4e2.fsf@stupidchicken.com> (raw)
In-Reply-To: <AANLkTim6651NJZXEa8V=dOW747go=2qdN1jr0LBt-JZV@mail.gmail.com> (Juanma Barranquero's message of "Tue, 17 Aug 2010 01:06:15 +0200")

Juanma Barranquero <lekktu@gmail.com> 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)))




  reply	other threads:[~2010-08-18 21:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-14 23:15 shrink-window-if-larger-than-buffer in VC-diff Chong Yidong
2010-08-15  1:14 ` Miles Bader
2010-08-15  7:07 ` Andreas Schwab
2010-08-15  9:38 ` annoyances [Was: shrink-window-if-larger-than-buffer in VC-diff] Uday S Reddy
2010-08-15 10:06   ` annoyances David Kastrup
2010-08-15 10:33     ` annoyances Uday S Reddy
2010-08-15 14:12   ` annoyances [Was: shrink-window-if-larger-than-buffer in VC-diff] Stephen J. Turnbull
2010-08-15 18:35     ` Uday S Reddy
2010-08-16  1:45       ` Stephen J. Turnbull
2010-08-16  8:54         ` Uday S Reddy
2010-08-15 22:44 ` shrink-window-if-larger-than-buffer in VC-diff Juanma Barranquero
2010-08-16  3:10   ` Chong Yidong
2010-08-16 23:06     ` Juanma Barranquero
2010-08-18 21:53       ` Chong Yidong [this message]
2010-08-20  9:06         ` martin rudalics
2012-10-27 13:45     ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxsjy4e2.fsf@stupidchicken.com \
    --to=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=lekktu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).