7

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

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

然后我决定打开 slime repl,Emacs 将垂直拆分其中一个水平窗格:

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

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

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

有什么简单的方法可以从 Emacs 自动给我的安排中获得我想要的安排(例如旋转安排),还是我自己明确关闭并重新拆分窗口?

编辑 | 如果我当前正在使用完整的水平拆分,或者实际上不可能,我是否可以直接打开完整的垂直拆分也很好奇。

4

3 回答 3

4

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

EmacsWiki上的项目管理页面上有更多内容。

对于您的第二个问题,这是我在配置中翻转水平/垂直拆分的内容(来源: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)
于 2013-07-02T13:50:11.587 回答
3

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

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

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

请注意,窗口配置转换确实需要删除并重新创建拆分,因此原始窗口对象并非都在该过程中存活。在这方面,实际上不可能按照您的要求去做。但对于大多数目的,“伪装”就足够了。

于 2013-07-01T23:58:27.843 回答
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列表以您描述的方式重新排列窗口。

于 2013-07-02T16:44:07.850 回答