unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Popping up a custom-shaped window compatible with quit-window
@ 2012-11-10 22:05 Roland Winkler
  2012-11-12  9:58 ` martin rudalics
  0 siblings, 1 reply; 3+ messages in thread
From: Roland Winkler @ 2012-11-10 22:05 UTC (permalink / raw)
  To: emacs-devel

BBDB uses the function bbdb-pop-up-window whenever it needs to pop
up a BBDB buffer. This function implements some hackery to make sure
that the BBDB window appears with a custom size where the user
expects it to be. Yet the algorithm is not compatible with
quit-window: If BBDB splits an existing window to display the BBDB
window, quit-window applied to the newly created BBDB window does
not restore the old window configuration (as it is the case when
pop-to-buffer splits a window).

What is the best way to achieve compatibility with quit-window?
Unfortunately, I do not know too much about the details of how emacs
is doing these things. While I have recently cleaned up BBDB
(including the code of bbdb-pop-up-window), the underlying algorithm
used by bbdb-pop-up-window is still the same that BBDB has used for
many years. Possibly the whole approach implemented in
bbdb-pop-up-window is not quite compatible anymore with how this
should be implemented nowadays. Or there is a simple solution to the
quit-window problem that I just do not know about.

I browsed through the long thread of Emacs Bug#1806, which is kind
of related, in the sense that BBDB wants to pop up its window such
that the new window "fits best" into the overall window layout of
the frame. Yet this thread left me clueless.

Any comments or suggestions are appreciated.


BBDB is available at
http://savannah.nongnu.org/projects/bbdb/
To check it out, use
git clone git://git.savannah.nongnu.org/bbdb.git



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Popping up a custom-shaped window compatible with quit-window
  2012-11-10 22:05 Popping up a custom-shaped window compatible with quit-window Roland Winkler
@ 2012-11-12  9:58 ` martin rudalics
  2012-11-13  2:41   ` Roland Winkler
  0 siblings, 1 reply; 3+ messages in thread
From: martin rudalics @ 2012-11-12  9:58 UTC (permalink / raw)
  To: Roland Winkler; +Cc: emacs-devel

 > BBDB uses the function bbdb-pop-up-window whenever it needs to pop
 > up a BBDB buffer.

I have problems understanding `bbdb-pop-up-window'.  What does

                         (split-window-horizontally
                          (if (integerp b-width)
                              (- (window-width window) b-width)
                            (round (* (- 1 b-width) (window-width window)))))
                         (select-window (next-window window))
                         (let (pop-up-windows)
                           (switch-to-buffer (get-buffer-create bbdb-buffer-name)))

intend to do?  IIUC

                         (select-window (next-window window))

is supposed to select the window returned by
`split-window-horizontally'.  I'd rather (1) use the return value of the
latter directly and (2) not select the window here.

                         (let (pop-up-windows)
                           (switch-to-buffer (get-buffer-create bbdb-buffer-name)))

I'd remove the binding to `pop-up-windows' here and use plain
`set-window-buffer' instead.  If you need to select the new window you
can do that afterwards.  All this for Emacsen < 24.

For Emacs 24 (where `display-buffer-record-window' is bound) do the same
but also add a call like

     (display-buffer-record-window 'window window buffer)

_before_ the `set-window-buffer' where WINDOW is the new window and
BUFFER the buffer you want to display in it.  This should record the
necessary information for `quit-window'.

For Emacs 24.3 it should be possible to use an alist entry with
`display-buffer-pop-up-window' and `window-height' and/or `window-width'
entries.  Take, for example

(defun bbdb-fix-width (window)
   (window-resize window -20 t))

(defun bbdb-fix-height (window)
   (window-resize window -10))

(display-buffer
  (get-buffer-create "*foo*")
  '(display-buffer-pop-up-window
    (window-width . bbdb-fix-width) (window-height . bbdb-fix-height)))

with appropriately modified `bbdb-fix-height' and `bbdb-fix-width'
functions (I was too lazy to figure them out here).  In this case
there's no need to record the window separately.

Note that if `bbdb-fix-width' or `bbdb-fix-height' fail to resize the
window appropriately, you have to live with the size supplied by
`split-window'.  If you don't like that, you have to write your own
`split-window-preferred-function' and bind it around the
`display-buffer' call.  If you write your own
`split-window-preferred-function', you can obviously also use it for
earlier Emacsen - no window recording is needed in that case either.

martin



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Popping up a custom-shaped window compatible with quit-window
  2012-11-12  9:58 ` martin rudalics
@ 2012-11-13  2:41   ` Roland Winkler
  0 siblings, 0 replies; 3+ messages in thread
From: Roland Winkler @ 2012-11-13  2:41 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

Thanks a lot, your detailed reply is very helpful! The next couple
of days I am rather busy with other stuff. I might get back to you
once more in a couple of days.

Roland



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-11-13  2:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-10 22:05 Popping up a custom-shaped window compatible with quit-window Roland Winkler
2012-11-12  9:58 ` martin rudalics
2012-11-13  2:41   ` Roland Winkler

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).