unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* pop-to-buffer behavior
@ 2010-04-21  9:05 Thierry Volpiatto
  2010-04-21 14:23 ` martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Volpiatto @ 2010-04-21  9:05 UTC (permalink / raw)
  To: emacs-devel

Hi all,
i have three windows, 2 with the same buffer (foo.el) splitted in two
and one with another buffer say *scratch*.

point is -|-

   +---------------+--------------+
   |               |              |
   |   -|-foo.el   |  foo.el      |
   |               |              |
   +---------------+--------------+
   |                              |
   |            *scratch*         |
   |                              |
   +------------------------------+

Here the code:(sit-for is just to see point moving)

,----
| (let ((buf (current-buffer)))
|    (pop-to-buffer "*scratch*") (sit-for 2) (pop-to-buffer buf))
`----

Ok, that work as expected, point is now again in the left buffer foo.el.

Now put point in the right side foo.el, and eval same code again, point
is now in the left side foo.el buffer.

I would like point come back at original place (right foo.el)

The purpose is to know if a particular buffer is actually visible in
this window:(work fine in most case, but not in this one)

,----
| (defun ioccur-visible-buffer-p (buffer)
|   "Can i see this buffer in this window."
|   (let ((buf        (current-buffer))
|         (cur-w-conf (current-window-configuration)))
|     (or (eq buf (get-buffer buffer))
|         (save-window-excursion
|           (pop-to-buffer buffer)
|           (pop-to-buffer buf)
|           ;; If BUFFER is NOT in same window than BUF
|           ;; We should have now another window configuration.
|           (compare-window-configurations
|            cur-w-conf (current-window-configuration))))))
`----

Any idea?

Thanks.
--
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/






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

* Re: pop-to-buffer behavior
  2010-04-21  9:05 pop-to-buffer behavior Thierry Volpiatto
@ 2010-04-21 14:23 ` martin rudalics
  2010-04-21 18:23   ` Thierry Volpiatto
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2010-04-21 14:23 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: emacs-devel

 > The purpose is to know if a particular buffer is actually visible in
 > this window:(work fine in most case, but not in this one)

`pop-to-buffer' gives no guarantee which window it selects when the same
buffer appears in several windows at once.  Also, using `pop-to-buffer'
for checking buffer-window associations is probably a bad idea.

If `buffer' denotes the "particular buffer" and "this window" means the
selected window why not simply use (eq (window-buffer) buffer) instead?

martin




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

* Re: pop-to-buffer behavior
  2010-04-21 14:23 ` martin rudalics
@ 2010-04-21 18:23   ` Thierry Volpiatto
  2010-04-21 18:37     ` Thierry Volpiatto
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Volpiatto @ 2010-04-21 18:23 UTC (permalink / raw)
  To: emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> The purpose is to know if a particular buffer is actually visible in
>> this window:(work fine in most case, but not in this one)
>
> `pop-to-buffer' gives no guarantee which window it selects when the same
> buffer appears in several windows at once.  Also, using `pop-to-buffer'
> for checking buffer-window associations is probably a bad idea.
>
> If `buffer' denotes the "particular buffer" and "this window" means the
> selected window why not simply use (eq (window-buffer) buffer) instead?

No that's doesn't work, i finally end up with this: :-)

,----
| (defun ioccur-visible-buffer-p (buffer)
|   "Can i see this buffer in this window."
|   (let* ((cur-w-conf (current-window-configuration)))
|     (or (eq buf (get-buffer buffer))
|         (save-window-excursion
|           (save-selected-window
|             (pop-to-buffer buffer))
|           ;; If BUFFER is NOT in same window than BUF
|           ;; We should have now another window configuration.
|           (compare-window-configurations
|            cur-w-conf (current-window-configuration))))))
`----


What i needed is `save-selected-window'.

-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/





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

* Re: pop-to-buffer behavior
  2010-04-21 18:23   ` Thierry Volpiatto
@ 2010-04-21 18:37     ` Thierry Volpiatto
  2010-04-21 20:31       ` martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Volpiatto @ 2010-04-21 18:37 UTC (permalink / raw)
  To: emacs-devel

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> martin rudalics <rudalics@gmx.at> writes:
>
>>> The purpose is to know if a particular buffer is actually visible in
>>> this window:(work fine in most case, but not in this one)
>>
>> `pop-to-buffer' gives no guarantee which window it selects when the same
>> buffer appears in several windows at once.  Also, using `pop-to-buffer'
>> for checking buffer-window associations is probably a bad idea.
>>
>> If `buffer' denotes the "particular buffer" and "this window" means the
>> selected window why not simply use (eq (window-buffer) buffer) instead?
>
> No that's doesn't work, i finally end up with this: :-)
>
> ,----
> | (defun ioccur-visible-buffer-p (buffer)
> |   "Can i see this buffer in this window."
> |   (let* ((cur-w-conf (current-window-configuration)))
> |     (or (eq buf (get-buffer buffer))
> |         (save-window-excursion
> |           (save-selected-window
> |             (pop-to-buffer buffer))
> |           ;; If BUFFER is NOT in same window than BUF
> |           ;; We should have now another window configuration.
> |           (compare-window-configurations
> |            cur-w-conf (current-window-configuration))))))
> `----
>
>
> What i needed is `save-selected-window'.

But what i really need is to read more carefully elisp manual:

`get-buffer-window' work perfectly.

Thank you Stefan ;-) and Martin also.

-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/





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

* Re: pop-to-buffer behavior
  2010-04-21 18:37     ` Thierry Volpiatto
@ 2010-04-21 20:31       ` martin rudalics
  2010-04-21 21:08         ` Thierry Volpiatto
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2010-04-21 20:31 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: emacs-devel

 > `get-buffer-window' work perfectly.

Since your buffer appears in two windows simultaneously,
`get-buffer-window-list' is probably what you want.

martin




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

* Re: pop-to-buffer behavior
  2010-04-21 20:31       ` martin rudalics
@ 2010-04-21 21:08         ` Thierry Volpiatto
  0 siblings, 0 replies; 6+ messages in thread
From: Thierry Volpiatto @ 2010-04-21 21:08 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> `get-buffer-window' work perfectly.
>
> Since your buffer appears in two windows simultaneously,
> `get-buffer-window-list' is probably what you want.

No, it's working like that (with get-buffer-window), i only want to know
if buffer is visible, duplicated or not.

What i was doing before was comparing the windows configurations, so
it's was important to come back in the initial buffer for comparing.

So if i have buffers A, B, C, D in current frame, i do
(get-buffer-window A)==> ok buffer A is visible
with A, A, B, C ==> same it's ok buffer A is visible.
with B, C, D ==> nil, buffer A is not visible.

And i do a different thing if buffer is visible or not.
(That's for ioccur.el)

But thanks for get-buffer-window-list, i will also need it for other
purpose ;-)

-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/




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

end of thread, other threads:[~2010-04-21 21:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-21  9:05 pop-to-buffer behavior Thierry Volpiatto
2010-04-21 14:23 ` martin rudalics
2010-04-21 18:23   ` Thierry Volpiatto
2010-04-21 18:37     ` Thierry Volpiatto
2010-04-21 20:31       ` martin rudalics
2010-04-21 21:08         ` Thierry Volpiatto

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