Pete's Linux Advent Calendar 2008

The 15th day

Transpose buffers in Emacs

You know that Ctrl-t will transpose characters? Do you also know that with M-t you transpose words? Now here is a function that will transpose buffers that you can put in your ~/.emacs:
(defun transpose-buffers-windows ()
  "Put current buffer in other window and vice versa."
  (interactive)
  (if (one-window-p t)
      (error "only displaying one window")
    (let* ((cb (current-buffer))
	   (ob (window-buffer (next-window))))
      (switch-to-buffer ob)
      (switch-to-buffer-other-window cb))))
(global-set-key "\C-xt" 'transpose-buffers-windows)
In Emacs use then Ctrl-x t to switch buffers.
Pete's Linux Advent Calendar 2008

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram