From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: how can I run commands when window displays a different buffer? Date: Sun, 29 Oct 2017 21:52:27 -0400 Message-ID: References: <59F32C2F.8020701@gmx.at> <87lgjw90k8.fsf@gmail.com> <59F4439F.60306@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1509328414 12287 195.159.176.226 (30 Oct 2017 01:53:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 30 Oct 2017 01:53:34 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 30 02:53:28 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8zGY-0002IO-MU for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Oct 2017 02:53:26 +0100 Original-Received: from localhost ([::1]:38341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8zGg-0004Nd-0J for geh-help-gnu-emacs@m.gmane.org; Sun, 29 Oct 2017 21:53:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8zG2-0004NA-Q6 for help-gnu-emacs@gnu.org; Sun, 29 Oct 2017 21:52:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e8zFz-0001zT-Nm for help-gnu-emacs@gnu.org; Sun, 29 Oct 2017 21:52:54 -0400 Original-Received: from [195.159.176.226] (port=41694 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e8zFz-0001yn-GI for help-gnu-emacs@gnu.org; Sun, 29 Oct 2017 21:52:51 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1e8zFk-0005od-Tr for help-gnu-emacs@gnu.org; Mon, 30 Oct 2017 02:52:36 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 35 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:5shdBJEMNjZWNI86gEpASFsd5Rk= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:114697 Archived-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