Emacs重新排列分裂窗格

时间:2013-07-01 23:28:14

标签: emacs

如果我在(终端)Emacs工作并且在屏幕上使用水平分割有2个缓冲区:

+--------------------------+
|                          |
|                          |
|                          |
|                          |
+--------------------------+
|                          |
|                          |
|                          |
|                          |
+--------------------------+

然后我决定打开粘液复制品,Emacs将垂直拆分其中一个水平窗格:

+--------------------------+
|                          |
|                          |
|                          |
|                          |
+-------------+------------+
|             |            |
|             |  slime     |
|             |            |
|             |            |
+-------------+------------+

但我想要的是使用窗户的整个高度在右边粘液:

+-------------+------------+
|             |            |
|             |            |
|             |            |
|             |            |
+-------------+  slime     |
|             |            |
|             |            |
|             |            |
|             |            |
+-------------+------------+

有没有简单的方法可以从Emacs自动给我的安排,到我想要的那个(例如旋转安排),还是我自己明确关闭并重新拆分窗户?

编辑|如果我现在正在使用完整的水平分割,或者如果它实际上是不可能的话,我可以直接打开一个完整的垂直分割。

3 个答案:

答案 0 :(得分:4)

如果您喜欢预先设置的窗口配置,请查看“工作区管理”页面:

EmacsWiki上的project management页面上还有更多内容。

关于第二个问题,以下是我在配置中翻转水平/垂直分割的信息(信用:https://github.com/yyr/emacs.d):

(defun split-window-func-with-other-buffer (split-function)
  (lexical-let ((s-f split-function))
    (lambda ()
      (interactive)
      (funcall s-f)
      (set-window-buffer (next-window) (other-buffer)))))

(defun split-window-horizontally-instead ()
  (interactive)
  (save-excursion
    (delete-other-windows)
    (funcall (split-window-func-with-other-buffer 'split-window-horizontally))))

(defun split-window-vertically-instead ()
  (interactive)
  (save-excursion
    (delete-other-windows)
    (funcall (split-window-func-with-other-buffer 'split-window-vertically))))

(global-set-key "\C-x|" 'split-window-horizontally-instead)
(global-set-key "\C-x_" 'split-window-vertically-instead)

答案 1 :(得分:3)

肯定有用于转换框架窗口配置(翻转,旋转等)的库,以及用于通过可用窗口旋转可见缓冲区的其他库。结合这些将实现您的目标。

我喜欢前者的TransposeFrame,我至少可以看到后者的几个选项:

一般来说,Wiki上的CategoryWindows应该对您有用。

请注意,窗口配置转换 do 需要删除并重新创建拆分,因此原始窗口对象不会全部在此过程中存活。在这方面, 实际上不可能做你所要求的事情;但对于大多数用途来说,“假装”就足够了。

答案 2 :(得分:1)

这是一个能够做你想要的功能。将其加载到emacs后,选择要重新排列的缓冲区并执行M-x my-shift-window-right。您还可以使用global-set-key将其绑定到密钥。

(defun my-shift-window-right (&optional start-window)
  "Reset the current window configuration with START-WINDOW
on the right and the rest of the windows on the left. START-WINDOW defaults to
the selected window. Return START-WINDOW, or nil if START-WINDOW isn't live or
if there is only one visible window."
  (interactive (list (selected-window)))
  (if (or (one-window-p)
          (and start-window
               (not (window-live-p start-window)))) nil
    (let ((other-buffers '())
          (start-window (or start-window (selected-window))))
      ;; add all visible buffers other than the current one to other-buffers list
      (walk-windows #'(lambda (window)
                        (when (not (eq window start-window))
                          (add-to-list 'other-buffers (window-buffer window)))))
      (delete-other-windows)
      ;; pop the first "other buffer" into a split window on the left
      (set-window-buffer (select-window (split-window start-window nil 'left))
                         (pop other-buffers))
      ;; make a split window for each buffer in the "other-buffers" list
      ;; select the start-window and return it when finished
      (dolist (buffer other-buffers (select-window start-window))
        (set-window-buffer (split-window (selected-window) nil 'above) buffer)))))

此函数循环显示其他可见窗口,并将每个缓冲区存储在名为other-buffers的列表中。然后,它通过迭代other-buffers列表重新排列窗口。