我在Emacs打开了2个窗口,我想交换他们的位置.
即考虑在源文件上面有一个REPL,我想交换它们的位置,以便REPL低于源文件.
我也想保留窗户的大小
我无耻地从Steve Yegge的.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上进行了测试