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

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

Re: swaping buffers


From: Floyd L. Davidson
Subject: Re: swaping buffers
Date: Fri, 17 Mar 2006 03:32:26 -0900
User-agent: gnus 5.10.6/XEmacs 21.4.15/Linux 2.6.5

"dydimustk" <dydimustk@gmail.com> wrote:
>It doesn't quite do what I want.
>I'm using different buffers in top half than I am in the bottom half.
>And I want to specifically swap out the top and bottom half without
>losing the buffer sizes.

Did you actually mean to say that you have two windows, top and
bottom, which you want to remain the same size while the buffers
being display in each is changed?  For example, the top window is
always larger no matter which buffer is being display.

Here is a function which more or less does that, and works in
both Emacs and XEmacs.  (It isn't well tested and may have a
surprise or two...)  If there are three buffers displayed, it
flips between the current buffer and the one below it, or the
top buffer if the bottom buffer is current.

I've added comments to indicate what it is doing.

(defun fld-flip-buffers ()
"Flip buffers between two windows."
(interactive)
(if (not(one-window-p 't))     ; do nothing for only 1 window
  (let ((w1 (selected-window)) ; save current window
        (w2 (next-window))     ; save "next window"
        (b1 (current-buffer))) ; save current buffer
     (select-window w2)        ; switch to "next window"
     (set-window-buffer w1
        (current-buffer))      ; display that buf in this window
     (set-window-buffer w2 b1) ; display this buf in that window
     (select-window w1))))     ; switch back to that window

Put that into your init file and bind it to some convenient key sequence.
For example, this binds it to the F5 function key:

  (define-key global-map  [f5]  'fld-flip-buffers)

-- 
Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@apaflo.com


reply via email to

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