help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how can I run commands when window displays a different buffer?


From: Amos Bird
Subject: Re: how can I run commands when window displays a different buffer?
Date: Sat, 28 Oct 2017 16:56:23 +0800
User-agent: mu4e 0.9.19; emacs 25.3.1


Hi martin,

This works pretty well. Thank you!

regards,

martin rudalics <address@hidden> 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
address@hidden


reply via email to

[Prev in Thread] Current Thread [Next in Thread]