all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how can I run commands when window displays a different buffer?
@ 2017-10-27 12:04 Amos Bird
  2017-10-27 12:18 ` Kaushal Modi
  0 siblings, 1 reply; 8+ messages in thread
From: Amos Bird @ 2017-10-27 12:04 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org


Hi,

I know there is a window-configuration-change-hook that covers 
this. But I need only the subset of the hook. What can I do? 

regards,

-- 
Amos Bird
amosbird@gmail.com



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

* Re: how can I run commands when window displays a different buffer?
  2017-10-27 12:04 Amos Bird
@ 2017-10-27 12:18 ` Kaushal Modi
  2017-10-27 12:46   ` Amos Bird
  0 siblings, 1 reply; 8+ messages in thread
From: Kaushal Modi @ 2017-10-27 12:18 UTC (permalink / raw)
  To: Amos Bird; +Cc: help-gnu-emacs@gnu.org

On Fri, Oct 27, 2017 at 8:05 AM Amos Bird <amosbird@gmail.com> wrote:

> I know there is a window-configuration-change-hook that covers
> this. But I need only the subset of the hook. What can I do?
>

The question is too broad.. "window displays a different buffer" -- That
can happen by dozens of different commands: find-file, switch-to-buffer,
pop-to-buffer, etc.

What is your exact use case?
-- 

Kaushal Modi


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

* Re: how can I run commands when window displays a different buffer?
  2017-10-27 12:18 ` Kaushal Modi
@ 2017-10-27 12:46   ` Amos Bird
  0 siblings, 0 replies; 8+ messages in thread
From: Amos Bird @ 2017-10-27 12:46 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: help-gnu-emacs@gnu.org

 
Hi Modi,

I'd like to add a (recenter) command after all these commands.

regards,

Kaushal Modi <kaushal.modi@gmail.com> writes:

> On Fri, Oct 27, 2017 at 8:05 AM Amos Bird <amosbird@gmail.com> wrote:
>
>> I know there is a window-configuration-change-hook that covers
>> this. But I need only the subset of the hook. What can I do?
>>
>
> The question is too broad.. "window displays a different buffer" -- That
> can happen by dozens of different commands: find-file, switch-to-buffer,
> pop-to-buffer, etc.
>
> What is your exact use case?


-- 
Amos Bird
amosbird@gmail.com



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

* Re: how can I run commands when window displays a different buffer?
@ 2017-10-27 12:53 martin rudalics
  2017-10-27 13:34 ` Amos Bird
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2017-10-27 12:53 UTC (permalink / raw)
  To: amosbird; +Cc: help-gnu-emacs

In a function on ‘window-configuration-change-hook’ you have to remember
all window-buffer associations in a list, removing defunct windows from
that list.  If you find a window whose association changed since the
last time that hook was run (and maybe also if you find a new window),
you know that that "window displays a different buffer" now.

martin




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

* Re: how can I run commands when window displays a different buffer?
  2017-10-27 12:53 how can I run commands when window displays a different buffer? martin rudalics
@ 2017-10-27 13:34 ` Amos Bird
  2017-10-28  8:45   ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: Amos Bird @ 2017-10-27 13:34 UTC (permalink / raw)
  To: martin rudalics; +Cc: help-gnu-emacs

 
Thanks martin!

I was thinking the similar but cannot find a way to construct the 
window-buffer associations. Do you mind giving me some hint :)

regards,

martin rudalics <rudalics@gmx.at> writes:

> In a function on ‘window-configuration-change-hook’ you have to remember
> all window-buffer associations in a list, removing defunct windows from
> that list.  If you find a window whose association changed since the
> last time that hook was run (and maybe also if you find a new window),
> you know that that "window displays a different buffer" now.
>
> martin


-- 
Amos Bird
amosbird@gmail.com



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

* Re: how can I run commands when window displays a different buffer?
  2017-10-27 13:34 ` Amos Bird
@ 2017-10-28  8:45   ` martin rudalics
  2017-10-28  8:56     ` Amos Bird
  2017-10-30  1:52     ` Stefan Monnier
  0 siblings, 2 replies; 8+ messages in thread
From: martin rudalics @ 2017-10-28  8:45 UTC (permalink / raw)
  To: Amos Bird; +Cc: help-gnu-emacs

 > I was thinking the similar but cannot find a way to construct the
 > window-buffer associations. Do you mind giving me some hint :)

The code below should do that.


(defun update-window-buffer-list ()
   (let ((old (frame-parameter nil 'window-buffer-list))
	new this)
     (walk-window-tree
      (lambda (window)
        (let ((old-buffer (cdr (assq window old)))
	     (new-buffer (window-buffer window)))
	 (unless (eq old-buffer new-buffer)
	   ;; The buffer of a previously existing window has changed or
	   ;; a new window has been added to this frame.
	   (ding))
	 (setq new (cons (cons window new-buffer) new)))))
     (set-frame-parameter nil 'window-buffer-list new)))

(add-hook 'window-configuration-change-hook 'update-window-buffer-list)


You can write a more destructive version using ‘setcdr’.

martin




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

* Re: how can I run commands when window displays a different buffer?
  2017-10-28  8:45   ` martin rudalics
@ 2017-10-28  8:56     ` Amos Bird
  2017-10-30  1:52     ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Amos Bird @ 2017-10-28  8:56 UTC (permalink / raw)
  To: martin rudalics; +Cc: help-gnu-emacs


Hi martin,

This works pretty well. Thank you!

regards,

martin rudalics <rudalics@gmx.at> writes:

>> I was thinking the similar but cannot find a way to construct 
>> the
>> window-buffer associations. Do you mind giving me some hint :)
>
> The code below should do that.
>
>
> (defun update-window-buffer-list ()
>   (let ((old (frame-parameter nil 'window-buffer-list))
> 	new this)
>     (walk-window-tree
>      (lambda (window)
>        (let ((old-buffer (cdr (assq window old)))
> 	     (new-buffer (window-buffer window)))
> 	 (unless (eq old-buffer new-buffer)
> 	   ;; The buffer of a previously existing window has changed 
> or
> 	   ;; a new window has been added to this frame.
> 	   (ding))
> 	 (setq new (cons (cons window new-buffer) new)))))
>     (set-frame-parameter nil 'window-buffer-list new)))
>
> (add-hook 'window-configuration-change-hook 
> 'update-window-buffer-list)
>
>
> You can write a more destructive version using ‘setcdr’.
>
> martin


--
Amos Bird
amosbird@gmail.com


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

* Re: how can I run commands when window displays a different buffer?
  2017-10-28  8:45   ` martin rudalics
  2017-10-28  8:56     ` Amos Bird
@ 2017-10-30  1:52     ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2017-10-30  1:52 UTC (permalink / raw)
  To: help-gnu-emacs

> The code below should do that.

> (defun update-window-buffer-list ()
>   (let ((old (frame-parameter nil 'window-buffer-list))
> 	new this)
>     (walk-window-tree
>      (lambda (window)
>        (let ((old-buffer (cdr (assq window old)))
> 	     (new-buffer (window-buffer window)))
> 	 (unless (eq old-buffer new-buffer)
> 	   ;; The buffer of a previously existing window has changed or
> 	   ;; a new window has been added to this frame.
> 	   (ding))
> 	 (setq new (cons (cons window new-buffer) new)))))
>     (set-frame-parameter nil 'window-buffer-list new)))

> (add-hook 'window-configuration-change-hook 'update-window-buffer-list)

> You can write a more destructive version using ‘setcdr’.

Hmm... why use a frame-parameter rather than a window-parameter?

 (defun update-window-buffer-list ()
   (walk-window-tree
    (lambda (window)
      (let ((old-buffer (window-parameter window 'my-last-buffer))
            (new-buffer (window-buffer window)))
        (unless (eq old-buffer new-buffer)
 	  ;; The buffer of a previously existing window has changed or
 	  ;; a new window has been added to this frame.
 	  (ding)
          (setf (window-parameter window 'my-last-buffer) new-buffer))))))


-- Stefan




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

end of thread, other threads:[~2017-10-30  1:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-27 12:53 how can I run commands when window displays a different buffer? martin rudalics
2017-10-27 13:34 ` Amos Bird
2017-10-28  8:45   ` martin rudalics
2017-10-28  8:56     ` Amos Bird
2017-10-30  1:52     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2017-10-27 12:04 Amos Bird
2017-10-27 12:18 ` Kaushal Modi
2017-10-27 12:46   ` Amos Bird

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.