all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: how can I run commands when window displays a different buffer?
Date: Sun, 29 Oct 2017 21:52:27 -0400	[thread overview]
Message-ID: <jwva809xvbi.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 59F4439F.60306@gmx.at

> 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




  parent reply	other threads:[~2017-10-30  1:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- 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

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

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

  git send-email \
    --in-reply-to=jwva809xvbi.fsf-monnier+gmane.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    /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 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.