From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.help Subject: Re: Q: How can I swap buffers in two windows? Date: Thu, 22 Sep 2005 19:09:18 +0200 Message-ID: <4332E53E.6020004@student.lu.se> References: <1127403583.568067.179950@g43g2000cwa.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1127411038 28020 80.91.229.2 (22 Sep 2005 17:43:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 22 Sep 2005 17:43:58 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Sep 22 19:43:53 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EIV4X-0003Fb-Og for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Sep 2005 19:41:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EIV4X-0007uA-4n for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Sep 2005 13:41:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EIUy1-0003HN-Cs for help-gnu-emacs@gnu.org; Thu, 22 Sep 2005 13:34:41 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EIUxz-0003Fw-MT for help-gnu-emacs@gnu.org; Thu, 22 Sep 2005 13:34:40 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EIUth-0001DY-FG for help-gnu-emacs@gnu.org; Thu, 22 Sep 2005 13:30:13 -0400 Original-Received: from [81.228.8.83] (helo=pne-smtpout1-sn2.hy.skanova.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EIUZW-0003XA-If for help-gnu-emacs@gnu.org; Thu, 22 Sep 2005 13:09:22 -0400 Original-Received: from [192.168.123.121] (83.249.205.211) by pne-smtpout1-sn2.hy.skanova.net (7.2.060.1) id 4332AC7800015517; Thu, 22 Sep 2005 19:09:19 +0200 User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en Original-To: Eric Pement In-Reply-To: <1127403583.568067.179950@g43g2000cwa.googlegroups.com> X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:29640 Archived-At: Eric Pement wrote: >This request has appeared several times on this newsgroup, worded in >different ways, but has never been answered. I have already checked the >FAQ, M-x apropos, and the Emacs info pages. Can someone please give >help or direction here? > >I have an Emacs frame split into two windows, which may be split >vertically or horizontally. I would like a single command to swap or >exchange both windows, i.e., put buffer A into window B, and put buffer >B into window A. If there are not exactly two windows in the frame, >issue an error message. > >I know that I can do "C-x b", {B}, , "C-x o", "C-x b", {A}, , >but I want to execute it with a single command without typing out the >buffer names at all. Emacs already knows the names of the buffers in >each window, so why should I have to type them? > >My elisp skills are not well-developed, so I'm asking for help. I have >GNU Emacs version 21.3.50.8. Thanks in advance. > > Something like this perhaps: (defun rotate-window-buffers() (interactive) (let* ((windows (window-list)) (buffers (mapcar (lambda(w) (window-buffer w)) windows)) (wpoints (mapcar (lambda(w) (window-point w)) windows)) (w (pop windows)) ) (setq windows (reverse windows)) (push w windows) (setq windows (reverse windows)) (mapc (lambda(w) (let ((b (pop buffers)) (p (pop wpoints))) (set-window-buffer w b) (set-window-point w p))) windows)))