Answers:
内置的方法是使用寄存器。
例如用于C-xrwa保存当前窗口配置以注册一个。
然后,您可以使用内置绑定C-x1运行delete-other-windows
查看完单个文件后,使用C-xrja来弹出寄存器a中保存的窗口配置。
简而言之:
C-xrwa (将配置保存到寄存器中)
C-x1 (删除其他窗口)
C-xrja (重新应用保存的窗口配置)
我确实发现寄存器不方便,但是我使用自定义窗口配置堆栈来管理我的配置。
我有两个绑定将当前配置推送到堆栈,然后弹出并应用顶部配置。
因此,在您的场景中,我将执行推入绑定,然后执行Cx 1,然后执行弹出绑定。
这是代码:
(defvar winstack-stack '()
"A Stack holding window configurations.
Use `winstack-push' and
`winstack-pop' to modify it.")
(defun winstack-push()
"Push the current window configuration onto `winstack-stack'."
(interactive)
(if (and (window-configuration-p (first winstack-stack))
(compare-window-configurations (first winstack-stack) (current-window-configuration)))
(message "Current config already pushed")
(progn (push (current-window-configuration) winstack-stack)
(message (concat "pushed " (number-to-string
(length (window-list (selected-frame)))) " frame config")))))
(defun winstack-pop()
"Pop the last window configuration off `winstack-stack' and apply it."
(interactive)
(if (first winstack-stack)
(progn (set-window-configuration (pop winstack-stack))
(message "popped"))
(message "End of window stack")))
然后,您可以绑定winstack-push
喜欢的东西C-cC-u,并winstack-pop
以 C-cC-o轻松地跳来跳去。
我用winner-mode
。这是我的设置:
(winner-mode)
(global-set-key [f7] 'winner-undo)
(global-set-key [C-f7] 'winner-redo)
(global-set-key [f9] 'delete-other-windows)
(global-set-key [C-f9] 'delete-window)
我不知道是否可以使用书签标记布局或其他内容,但是对于我而言,能够连续切换回先前的布局就足够了。
Emacs提供了寄存器来保存和应用数据,例如您当前的窗口配置,这可以通过C-x r w
和来完成C-x r j
。但是,由于您需要记住窗口寄存器,因此这种方法变得笨拙。
有一些软件包可以改善这一点。iregister使此基本功能更易于检查和交互。我知道的其他人在不影响寄存器的情况下使用它,例如elscreen和escreen,它们使用标题栏显示选项卡。工作组和工作组2是解决此问题的两种更新,更广泛的方法。我个人都不喜欢它,因此写了我自己的介于两者之间的东西,希望它的错误和复杂性会减少。
(window-configuration-to-register "1")
在我的.emacs命令,但没有奏效
您可以将当前窗口布局保存到寄存器,然后使用还原它jump-to-register
。该命令默认window-configuration-to-register
绑定C-x r w
。
例如,当您以有用的方式排列窗口时,可以i
使用以下命令将它们保存为注册文件C-x r w i
,稍后使用来恢复布局C-x r j i
。
这是一个有趣的问题。几年前,我研究了所有解决方案。仅workgroups2.el的重量足以覆盖所有角落的情况。
但是workgroups2 UI是一场灾难。例如,如果启用worksgroup-mode(如其README所建议),则先前的布局将在emacs启动期间自动加载。这会使启动每次都很慢。
我的解决方案是将workgroups2视为API的集合,而不是开箱即用的可用工具。所以我通过使用@ abo-abo的ivy-mode(https://github.com/abo-abo/swiper)来更改其默认UI交互
切换整个窗口很容易,使用赢家模式的API就足够了。
下面是完整的代码(我只用M-x toggle-full-window
,M-x wg-create-workgroup
而且M-x my-wg-switch-workgroup
,你还需要安装刷卡,正如我上面提到)
(defun toggle-full-window()
"Toggle the full view of selected window"
(interactive)
;; @see http://www.gnu.org/software/emacs/manual/html_node/elisp/Splitting-Windows.html
(if (window-parent)
(delete-other-windows)
(winner-undo)))
(setq wg-use-default-session-file nil)
;; don't open last workgroup automatically in `wg-open-session',
;; I only want to check available workgroups! Nothing more.
(setq wg-load-last-workgroup nil)
(setq wg-open-this-wg nil)
;(workgroups-mode 1) ; put this one at the bottom of .emacs
;; by default, the sessions are saved in "~/.emacs_workgroups"
(autoload 'wg-create-workgroup "workgroups2" nil t)
(defun my-wg-switch-workgroup ()
(interactive)
(let (group-names selected-group)
(unless (featurep 'workgroups2)
(require 'workgroups2))
(setq group-names
(mapcar (lambda (group)
;; re-shape list for the ivy-read
(cons (wg-workgroup-name group) group))
(wg-session-workgroup-list (read (f-read-text (file-truename wg-session-file))))))
(ivy-read "work groups" group-names
:action (lambda (group)
(wg-find-session-file wg-default-session-file)
(wg-switch-to-workgroup group)))))
(eval-after-load 'workgroups2
'(progn
;; make sure wg-create-workgroup always success
(defadvice wg-create-workgroup (around wg-create-workgroup-hack activate)
(unless (file-exists-p (wg-get-session-file))
(wg-reset t)
(wg-save-session t))
(unless wg-current-session
;; code extracted from `wg-open-session'.
;; open session but do NOT load any workgroup.
(let ((session (read (f-read-text (file-truename wg-session-file)))))
(setf (wg-session-file-name session) wg-session-file)
(wg-reset-internal (wg-unpickel-session-parameters session))))
ad-do-it
;; save the session file in real time
(wg-save-session t))
(defadvice wg-reset (after wg-reset-hack activate)
(wg-save-session t))
;; I'm fine to to override the original workgroup
(defadvice wg-unique-workgroup-name-p (around wg-unique-workgroup-name-p-hack activate)
(setq ad-return-value t))))