我在Emacs打开了2个窗口,我想换掉他们的位置。
即考虑在源文件上面有一个REPL,我想交换它们的位置,以便REPL低于源文件。
我还想保留窗户的尺寸
答案 0 :(得分:7)
我无耻地从Steve Yegge's .emacs
偷走了这个(defun swap-windows ()
"If you have 2 windows, it swaps them."
(interactive)
(cond ((not (= (count-windows) 2)) (message "You need exactly 2 windows to do this."))
(t
(let* ((w1 (first (window-list)))
(w2 (second (window-list)))
(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)))))
在Gentoo上测试Emacs 23.1.1。这确实保留了窗口大小。
我也发现这个更清洁。
(defun transpose-windows ()
(interactive)
(let ((this-buffer (window-buffer (selected-window)))
(other-buffer (prog2
(other-window +1)
(window-buffer (selected-window))
(other-window -1))))
(switch-to-buffer other-buffer)
(switch-to-buffer-other-window this-buffer)
(other-window -1)))
还在Emacs 23.1.1上进行了测试
答案 1 :(得分:4)
以下版本适用于任意数量的窗口。当有两个以上的窗口时,重复的调用将使所选的缓冲区连续出现在每个窗口中。
(defun swap-buffer () (interactive) (cond ((one-window-p) (display-buffer (other-buffer))) ((let* ((buffer-a (current-buffer)) (window-b (cadr (window-list))) (buffer-b (window-buffer window-b))) (set-window-buffer window-b buffer-a) (switch-to-buffer buffer-b) (other-window 1)))))
答案 2 :(得分:2)
我发现TransposeFrame库很有用。根据这个问题,我主要使用它来交换两个窗口;但它提供了更多的通用功能。
点击链接查看各种转换的ascii图。
答案 3 :(得分:1)
见http://www.emacswiki.org/cgi-bin/wiki/buffer-move.el。您可以通过elpa
安装它