emacs - 使用emacs,如何交换2个窗口的位置

标签 emacs

我在 Emacs 中打开了 2 个窗口,我想交换它们的位置。

即考虑在源文件上方有一个 REPL,我想交换它们的位置,以便 REPL 位于源文件下方。

我还想保留窗口的大小

最佳答案

我无耻地从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 上进行了测试

关于emacs - 使用emacs,如何交换2个窗口的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1510091/

相关文章:

emacs - Emacs : Relationship between etags, ebrowse、cscope、GNU Global 和 exuberant ctags 的标签

git - 为什么要使用 Dropbox 和 Git 作为 Emacs 初始化文件?

macos - 在 OSX 上更新 emacs

macos - 如何在 OS X 上正确安装 emacs?

emacs - 如何存储持久的历史记录?

Emacs:如何读取我的键绑定(bind)?

emacs - 使用 tuareg 在 Emacs 中启动自定义 OCaml 顶层的便捷方式

emacs - 组织模式下的每周回顾

git - 禁用git中的所有分页

r - ESS和针织/编织: How to source the Rnw file into an interactive session?