是否有类似于 `delete-other-windows` (`C-x 1`) 的东西,但它允许我恢复我的 window 排列

Is there something similar to `delete-other-windows` (`C-x 1`), but that allows me to restore my window arrangement

假设我有一个缓冲区,它的当前 window 有点太拥挤,所以我决定我想简单地给它更多 space,然后回到我正在做的事情。我是否可以暂时 隐藏 其他 windows 而不是像 C-x 1 那样删除它们?

frame-cmds.el 有这方面的命令。它们本质上是标准 Emacs 命令的可重复版本,例如 enlarge-window

"repeatable" 我的意思是您可以重复按键序列的最后一次击键。

例如,默认情况下 C-x } 绑定到标准 Emacs 命令 enlarge-window-horizontally。要重复它,您需要每次都重复整个按键序列:C-x } C-x } C-x } ...。 (否则您需要为要扩大的列数提供数字前缀 arg window。)

但是可重复的版本,命令 enlarge-window-horizontally-repeat 让你只做 C-x } } } ...

定义很简单。他们使用这个辅助函数:

(defun repeat-command (command)
  "Repeat COMMAND."
  (require 'repeat)         ; Define its vars before we let-bind them.
  (let ((repeat-previous-repeated-command  command)
        (repeat-message-function           #'ignore)
        (last-repeatable-command           'repeat))
    (repeat nil)))

这就是 enlarge-window-horizontally-repeat 的全部定义:

(defun enlarge-window-horizontally-repeat ()
  "Enlarge selected window horizontally by one column.
You can repeat this by hitting the last key again..."
  (interactive)
  (require 'repeat)
  (frcmds-repeat-command 'enlarge-window-horizontally))

以下是您可能会使用的一些键绑定:

(global-set-key [remap enlarge-window-horizontally] 'enlarge-window-horizontally-repeat)
(global-set-key [remap shrink-window-horizontally]  'shrink-window-horizontally-repeat)
(global-set-key [remap enlarge-window]              'enlarge/shrink-window-repeat)

除此之外,还有标准的 Emacs 命令 shrink-window-if-larger-than-buffer,默认绑定到 C-x -。它缩小 window 以适合您的缓冲区内容。

您可以将 window 配置保存到寄存器,转到单个 window 完成后,从寄存器恢复 window 配置:

  • 将window配置保存到寄存器zC-xrwz
  • 转到一个window:C-x1然后做你需要做的(但不要打扰寄存器z!)
  • 从寄存器z恢复window配置:C-xrjz

执行 (info "(elisp)Registers") 获取有关 registers 的信息。执行C-hfwindow-配置注册RET 有关绑定到 C-xrw.[= 的函数的信息15=]

将此添加到您的初始文件中:

(winner-mode 1)

然后就可以正常使用C-x1,然后再使用C-c调用winner-undo恢复之前的window配置。

可以重复使用C-c返回之前的配置,C-c 再次跳回最新的

n.b。这是一个通用功能,除了这个特定示例之外,它在各种情况下都非常有用。我强烈建议熟悉它。