在 Emacs 中交換 buffer window

Steve Yegge 在他舊的 blog 中有一篇提供了一個 elisp function 可以交換 buffer window,但是他所提供的只能在兩個 buffer window 的狀態下交換,因此我做了一點修改,讓他可以在多個 buffer window 下也能運行。


(defun swap-windows ()
  "If you have more than 2 windows, it swaps them."
  (interactive)
  (cond ((< (count-windows) 2)
         (message "You need more than 2 windows to do this."))
        (t
         (let* ((wlst-from (window-list))
                (wlst-to (window-list))
                (welm (pop wlst-to)))
           (append wlst-to welm)
           (while (and wlst-from wlst-to)
             (let* ((w1 (pop wlst-from))
                    (w2 (pop wlst-to))
                    (b1 (window-buffer w1))
                    (b2 (window-buffer w2))
                    (s1 (window-start w1))
                    (s2 (window-start w2)))
               (set-window-buffer w1 b2)
               (set-window-buffer w2 b1)
               (set-window-start w1 s2)
               (set-window-start w2 s1)))))))

發表迴響

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

連結到 %s


Follow

Get every new post delivered to your Inbox.