unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
       [not found] <5167D3B7.2080408@gmx.at>
@ 2013-04-12 12:12 ` João Távora
  2013-04-12 13:13   ` João Távora
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: João Távora @ 2013-04-12 12:12 UTC (permalink / raw)
  To: martin rudalics; +Cc: help-gnu-emacs@gnu.org List, emacs-devel

On Fri, Apr 12, 2013 at 10:28 AM, martin rudalics <rudalics@gmx.at> wrote:

> `switch-to-buffer' uses `pop-to-buffer' to make sure the window
> displaying the buffer is selected.  You use `display-buffer' which
> doesn't necessarily make the window selected - IIUC you rely on the
> window manager to select the window.

yes, you understand correctly.

> Other from that I don't see anything hackish with your approach if the
> idea is to make `switch-to-buffer' do what you want when it's called
> from other code (which ideally should not happen).  In this case you
> might also want to advice `switch-to-buffer-other-window' accordingly.

I do want that precisely. `display-buffer-alist' apparently allows me (a LOT of)
control how `display-buffer' but not when it is called. The advice is because I
want ibuffer and ido to work with this as well.

The hackish part is was also that I call the predicate twice, but I can simplify
that...

(defadvice switch-to-buffer (around joaot/browse-buffer-maybe activate)
  (if (joaot/browse-buffer-p buffer-or-name nil)
      (let ((display-buffer-alist `(("" .
(joaot/browse-buffer-in-special-frame . nil)))))
        (display-buffer buffer-or-name))
    ad-do-it))

However, I still have to have to set `display-buffer-alist' globally for those
functions who call `display-buffer' directly, like `describe-function' does for
"*Help*" buffers, for example.

(setq display-buffer-alist
      `((joaot/browse-buffer-p . (joaot/browse-buffer-in-special-frame . nil))))

I'm quite happy with this functionally, and find this feature is quite useful to
keep focus on one frame, but be able to look at a secondary frame on a second
monitor for reference and only switching to it occasionally.

Ideally I would want anywthing with the meaning "switch to some buffer" (be it
`pop-to-buffer', `switch-to-buffer-other-window`, `display-buffer`, etc...) to
be be hookable at some common point, much as is already done with `display-
buffer'.

Or alternatively, and maybe simpler, if `display-buffer' is so powerful, why
can't it be used by `switch-to-buffer' and friends? I know `diplay-buffer''s
semantics are "display without selecting", but can't those be relaxed and the
"without selecting" part be just the default?

Another, distinct, small problem persists, and I suspect it has to do with not
understanding what the various alists are in the documentation of
`display-buffer'
and `display-buffer-alist'...

Specifically, how can I prevent `display-buffer' from stopping at one of
the actions that I specify in `display-buffer-alist'? For example,
`describe-function' shows me the buffer on the secondary "browse" frame" but
still keeps the current pop-to-frame behaviour. I'm going to have a look at
`display-buffer-overriding-alist', maybe that will do it.

Thanks
--
João Távora



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

* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
  2013-04-12 12:12 ` frames dedicated to buffers, or, always see specific buffers in a specific frame João Távora
@ 2013-04-12 13:13   ` João Távora
  2013-04-12 14:15   ` martin rudalics
  2013-04-12 16:45   ` Stefan Monnier
  2 siblings, 0 replies; 8+ messages in thread
From: João Távora @ 2013-04-12 13:13 UTC (permalink / raw)
  To: martin rudalics; +Cc: help-gnu-emacs@gnu.org List, emacs-devel

just a small update, this is the code I'm currently working with on
emacs 24.1.1 on windows:

(setq display-buffer-alist
      `((joaot/browse-buffer-p . (joaot/browse-buffer-in-special-frame . nil))))

(defvar joaot/browse-frame)
(setq joaot/browse-frame (new-frame))
(defun joaot/browse-buffer-p (buffer action)
  (declare (ignore action))
  (let ((buffer (and buffer
                     (get-buffer buffer))))
    (and (frame-live-p joaot/browse-frame)
         buffer
         (string-match "^\\*Help\\*$" (buffer-name buffer)) ;; or some
other predicate
         )))

(defun joaot/browse-buffer-in-special-frame (buffer alist)
  (set-window-buffer (frame-selected-window joaot/browse-frame) buffer))

(defadvice switch-to-buffer (around joaot/browse-buffer-maybe activate)
  (if (joaot/browse-buffer-p buffer-or-name nil)
      (let ((display-buffer-alist `(("" .
(joaot/browse-buffer-in-special-frame . nil)))))
        (display-buffer buffer-or-name))
    ad-do-it))



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

* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
  2013-04-12 12:12 ` frames dedicated to buffers, or, always see specific buffers in a specific frame João Távora
  2013-04-12 13:13   ` João Távora
@ 2013-04-12 14:15   ` martin rudalics
       [not found]     ` <CALDnm50Q=eNA6rgUS-DQD2RLuE=kyizGpYWyENVU=2Py+-MTig@mail.gmail.com>
  2013-04-12 16:45   ` Stefan Monnier
  2 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2013-04-12 14:15 UTC (permalink / raw)
  To: João Távora; +Cc: help-gnu-emacs@gnu.org List, emacs-devel

 >> `switch-to-buffer' uses `pop-to-buffer' to make sure the window
 >> displaying the buffer is selected.  You use `display-buffer' which
 >> doesn't necessarily make the window selected - IIUC you rely on the
 >> window manager to select the window.
 >
 > yes, you understand correctly.

So for making this general purpose you should use `pop-to-buffer'
instead of `display-buffer'.

 >> Other from that I don't see anything hackish with your approach if the
 >> idea is to make `switch-to-buffer' do what you want when it's called
 >> from other code (which ideally should not happen).  In this case you
 >> might also want to advice `switch-to-buffer-other-window' accordingly.
 >
 > I do want that precisely. `display-buffer-alist' apparently allows me (a LOT of)
 > control how `display-buffer' but not

... only, I presume ...

 > when it is called. The advice is because I
 > want ibuffer and ido to work with this as well.

These should refrain from using `switch-to-buffer(-...)' and use
`pop-to-buffer' with the `display-buffer-same-window' directive instead.
Wherever this bothers you, file a bug report so it gets fixed.

 > The hackish part is was also that I call the predicate twice, but I can simplify
 > that...
 >
 > (defadvice switch-to-buffer (around joaot/browse-buffer-maybe activate)
 >   (if (joaot/browse-buffer-p buffer-or-name nil)
 >       (let ((display-buffer-alist `(("" .
 > (joaot/browse-buffer-in-special-frame . nil)))))
 >         (display-buffer buffer-or-name))
 >     ad-do-it))
 >
 > However, I still have to have to set `display-buffer-alist' globally for those
 > functions who call `display-buffer' directly, like `describe-function' does for
 > "*Help*" buffers, for example.
 >
 > (setq display-buffer-alist
 >       `((joaot/browse-buffer-p . (joaot/browse-buffer-in-special-frame . nil))))
 >
 > I'm quite happy with this functionally, and find this feature is quite useful to
 > keep focus on one frame, but be able to look at a secondary frame on a second
 > monitor for reference and only switching to it occasionally.

I just don't understand whether you deliberately name buffers specially
to exploit this feature.  Couldn't you use some more human predicate for
this purpose?

 > Ideally I would want anywthing with the meaning "switch to some buffer" (be it
 > `pop-to-buffer', `switch-to-buffer-other-window`, `display-buffer`, etc...) to
 > be be hookable at some common point, much as is already done with `display-
 > buffer'.

This was the intention of `display-buffer-alist' and IIRC at some time I
had already removed all calls of `switch-to-buffer' from the Emacs code
base.  Somehow this got reverted later.

 > Or alternatively, and maybe simpler, if `display-buffer' is so powerful, why
 > can't it be used by `switch-to-buffer' and friends? I know `diplay-buffer''s
 > semantics are "display without selecting", but can't those be relaxed and the
 > "without selecting" part be just the default?

`switch-to-buffer' is the traditional means to interactively show a
buffer in the selected window.  It shouldn't be used in Lisp code.

 > Another, distinct, small problem persists, and I suspect it has to do with not
 > understanding what the various alists are in the documentation of
 > `display-buffer'
 > and `display-buffer-alist'...
 >
 > Specifically, how can I prevent `display-buffer' from stopping at one of
 > the actions that I specify in `display-buffer-alist'? For example,
 > `describe-function' shows me the buffer on the secondary "browse" frame" but
 > still keeps the current pop-to-frame behaviour. I'm going to have a look at
 > `display-buffer-overriding-alist', maybe that will do it.

This doesn't sound right.  When `display-buffer' has found a window it
should stop right there.  Anything else would constitute a bug.  If you
can reproduce it, step through it with the debugger to find out what
goes wrong.

martin



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

* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
  2013-04-12 12:12 ` frames dedicated to buffers, or, always see specific buffers in a specific frame João Távora
  2013-04-12 13:13   ` João Távora
  2013-04-12 14:15   ` martin rudalics
@ 2013-04-12 16:45   ` Stefan Monnier
  2013-04-13  8:01     ` martin rudalics
  2013-04-14 18:18     ` João Távora
  2 siblings, 2 replies; 8+ messages in thread
From: Stefan Monnier @ 2013-04-12 16:45 UTC (permalink / raw)
  To: João Távora
  Cc: martin rudalics, help-gnu-emacs@gnu.org List, emacs-devel

>> Other from that I don't see anything hackish with your approach if the
>> idea is to make `switch-to-buffer' do what you want when it's called
>> from other code (which ideally should not happen).  In this case you
>> might also want to advice `switch-to-buffer-other-window' accordingly.

I don't see why that would be necessary: switch-to-buffer-other-window
calls display-buffer (well, pop-to-buffer) so it should honor
display-buffer-alist.

> Ideally I would want anywthing with the meaning "switch to some
> buffer" (be it `pop-to-buffer', `switch-to-buffer-other-window`,
> `display-buffer`, etc...) to be be hookable at some common point, much
> as is already done with `display- buffer'.

Other than switch-to-buffer they all go through display-buffer and obey
the display-buffer-* hooks.

switch-to-buffer is special because there are various circumstances
where it's more important for it to only affect the selected-window then
it is to display the specified buffer.

> Specifically, how can I prevent `display-buffer' from stopping at one of
> the actions that I specify in `display-buffer-alist'?

Don't return nil?

More specifically, your joaot/browse-buffer-in-special-frame should
return the window it used to display the buffer.


        Stefan



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

* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
  2013-04-12 16:45   ` Stefan Monnier
@ 2013-04-13  8:01     ` martin rudalics
  2013-04-14 18:18     ` João Távora
  1 sibling, 0 replies; 8+ messages in thread
From: martin rudalics @ 2013-04-13  8:01 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: help-gnu-emacs@gnu.org List, João Távora, emacs-devel

 > I don't see why that would be necessary: switch-to-buffer-other-window
 > calls display-buffer (well, pop-to-buffer) so it should honor
 > display-buffer-alist.

Correct, obviously.

 > Other than switch-to-buffer they all go through display-buffer and obey
 > the display-buffer-* hooks.
 >
 > switch-to-buffer is special because there are various circumstances
 > where it's more important for it to only affect the selected-window then
 > it is to display the specified buffer.

Ideally, `switch-to-buffer' does not get called from Lisp code.
Unfortunately, there are too many instances of such calls to change them
all.

martin



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

* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
  2013-04-12 16:45   ` Stefan Monnier
  2013-04-13  8:01     ` martin rudalics
@ 2013-04-14 18:18     ` João Távora
  1 sibling, 0 replies; 8+ messages in thread
From: João Távora @ 2013-04-14 18:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: martin rudalics, help-gnu-emacs@gnu.org List, emacs-devel

On Fri, Apr 12, 2013 at 5:45 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> switch-to-buffer is special because there are various circumstances
> where it's more important for it to only affect the selected-window then
> it is to display the specified buffer.
>

Yes I see. And, according to Martin, it should only be called
interactively, and therefore you simple rebinding would work, but in
reality it isn't.

> More specifically, your joaot/browse-buffer-in-special-frame should
> return the window it used to display the buffer.

Thanks! that does it, should have read `display-buffer''s doc more
carefully. Shouldn't its machinery assert `windowp' somewhere?

-- 
João Távora



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

* frames dedicated to buffers, or, always see specific buffers in a specific frame
       [not found]     ` <CALDnm50Q=eNA6rgUS-DQD2RLuE=kyizGpYWyENVU=2Py+-MTig@mail.gmail.com>
@ 2013-04-14 18:42       ` João Távora
  2013-04-15  7:11         ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: João Távora @ 2013-04-14 18:42 UTC (permalink / raw)
  Cc: help-gnu-emacs, Stefan Monnier, emacs-devel

>> yes, you understand correctly.
>
> So for making this general purpose you should use `pop-to-buffer'
> instead of `display-buffer'.

Yes, that works too. Why exactly is this more general purpose?

>> control how `display-buffer' but not
>
> ... only, I presume ...

Sorry I mean "a lot of control over how it gets called, but not when
it gets called"

>> when it is called. The advice is because I
>> want ibuffer and ido to work with this as well.
>
> These should refrain from using `switch-to-buffer(-...)' and use
> `pop-to-buffer' with the `display-buffer-same-window' directive instead.
> Wherever this bothers you, file a bug report so it gets fixed.

it didn't bother me until now, let's see if I use this frequently...

 Also, ido has these `ido-default-buffer-method' and
`ido-default-file-method' that can be set to various options to
control how buffer appears.

But the way these options implemented does not bring them all to
`display-buffer', which sometimes precludes user's control. Should't
they be implemented via `display-buffer-alist', keeping any of the
user's entries on top?

> [...]  Couldn't you use some more human predicate for this purpose?

Yes, I could of course, but was too lazy. I could use any
buffer-checking predicate. There could be some kind of var
`joaot/browse-buffer-predicates' tried in order by
`joaot/browse-buffer-p'.

>
> This was the intention of `display-buffer-alist' and IIRC at some time I
> had already removed all calls of `switch-to-buffer' from the Emacs code
> base.  Somehow this got reverted later.

Pity. But what about making `switch-to-buffer' delegate to
`display-buffer' too? It could dinamically bind `display-buffer-alist'
to display and select the buffer, but keeping any existing entries
(probably set by the user, or other programs) on top.

If that resulted in `switch-to-buffer' not switching to the buffer's
window, it could not be considered unexpected behaviour, since
ultimately the user set `display-buffer-alist' himself.

> `switch-to-buffer' is the traditional means to interactively show a
> buffer in the selected window.  It shouldn't be used in Lisp code.

Yes I see. But see above for a (possibly naive) fix.

> This doesn't sound right.  When `display-buffer' has found a window it
> should stop right there.  Anything else would constitute a bug.  If you
> can reproduce it, step through it with the debugger to find out what
> goes wrong.

My fault, sorry. The function displaying the buffer must return a
window object, anything else results in funny behaviour.

Anyway, it's working nicely now, thanks for the help.

--
João Távora



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

* Re: frames dedicated to buffers, or, always see specific buffers in a specific frame
  2013-04-14 18:42       ` João Távora
@ 2013-04-15  7:11         ` martin rudalics
  0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2013-04-15  7:11 UTC (permalink / raw)
  To: João Távora; +Cc: help-gnu-emacs, Stefan Monnier, emacs-devel

 >> So for making this general purpose you should use `pop-to-buffer'
 >> instead of `display-buffer'.
 >
 > Yes, that works too. Why exactly is this more general purpose?

I meant that if you really want to use this as a subtitute for
`switch-to-buffer' you should make sure the window and frame get
selected.  They don't necessarily using `display-buffer' alone.

 >  Also, ido has these `ido-default-buffer-method' and
 > `ido-default-file-method' that can be set to various options to
 > control how buffer appears.
 >
 > But the way these options implemented does not bring them all to
 > `display-buffer', which sometimes precludes user's control. Should't
 > they be implemented via `display-buffer-alist', keeping any of the
 > user's entries on top?

Doesn't setting `ido-default-buffer-method' to `display' work?  Maybe we
could add `pop-to-buffer' to the default methods.

 > Pity. But what about making `switch-to-buffer' delegate to
 > `display-buffer' too? It could dinamically bind `display-buffer-alist'
 > to display and select the buffer, but keeping any existing entries
 > (probably set by the user, or other programs) on top.
 >
 > If that resulted in `switch-to-buffer' not switching to the buffer's
 > window, it could not be considered unexpected behaviour, since
 > ultimately the user set `display-buffer-alist' himself.

The basic idea of the `switch-to-buffer' functions is to bypass the
`display-buffer' customizations.  That is, by default you display a
buffer in a certain manner but always can use `switch-to-buffer' to
override that default behavior.

martin



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

end of thread, other threads:[~2013-04-15  7:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5167D3B7.2080408@gmx.at>
2013-04-12 12:12 ` frames dedicated to buffers, or, always see specific buffers in a specific frame João Távora
2013-04-12 13:13   ` João Távora
2013-04-12 14:15   ` martin rudalics
     [not found]     ` <CALDnm50Q=eNA6rgUS-DQD2RLuE=kyizGpYWyENVU=2Py+-MTig@mail.gmail.com>
2013-04-14 18:42       ` João Távora
2013-04-15  7:11         ` martin rudalics
2013-04-12 16:45   ` Stefan Monnier
2013-04-13  8:01     ` martin rudalics
2013-04-14 18:18     ` João Távora

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