所谓工作空间,是指需要保存当前打开的缓冲区状态(可能在用户指定的工作空间文件中),并快速切换到另一组打开的缓冲区,例如继续处理与另一个项目相关的文件。
是否有适用于Emacs的插件可以实现这一功能?你会推荐哪个?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; workgroups for windows
(setq wg-prefix-key (kbd "C-c z")
wg-no-confirm t
wg-file (concat emacs-persistence-directory "workgroups")
wg-use-faces nil
wg-switch-on-load nil)
(defun wg-load-default ()
"Run `wg-load' on `wg-file'."
(interactive)
(wg-load wg-file))
(defun wg-save-default ()
"Run `wg-save' on `wg-file'."
(interactive)
(when wg-list
(with-temp-message ""
(wg-save wg-file))))
(with-library 'workgroups
(define-key wg-map (kbd "C-l") 'wg-load-default)
(define-key wg-map (kbd "C-s") 'wg-save-default)
(workgroups-mode 1)
(add-hook 'auto-save-hook 'wg-save-default)
(add-hook 'kill-emacs-hook 'wg-save-default))
就我个人而言,我一直在使用`persp-mode':
这是一个基于Nathan Weizenbaum的
perspective-el
开发的emacs增强工具。它不仅可以实现多窗口之间的视角共享,还可以将当前的视角存储到文件中,方便再次恢复。
(provide 'my-revive-config)
(require 'windows) ; use this with revive so that window splits are recallable
; too
(win:startup-with-window) ; start with window 1
;;;[Key Bindings]
;;;
;;; The default prefix key stroke for Windows is `C-c C-w'. If it
;;; causes you some troubles, see the section `Customizations'.
;;; Here are the default key bindings.
;;;
;;; C-c C-w 1 Switch to window 1 (Q)
;;; C-c C-w 2 Switch to window 2 (Q)
;;; :
;;; C-c C-w 9 Switch to window 9 (Q)
;;; C-c C-w 0 Swap windows with the buffer 0 (Q)
;;; (Select unallocated frame(Emacs 19))
;;; C-c C-w SPC Switch to window previously shown (Q)
;;; C-c C-w C-n Switch to next window
;;; C-c C-w C-p Switch to previous window
;;; C-c C-w ! Delete current window (Q)
;;; C-c C-w C-w Window operation menu
;;; C-c C-w C-r Resume menu
;;; C-c C-w C-l Local resume menu
;;; C-c C-w C-s Switch task
;;; C-c C-w = Show window list (Q)
;;;
;;; The key strokes to select windows from 1 to 9 must be
;;; frequently used, so the alternative key strokes `C-c [Num.]' are
;;; available by default (And any function with (Q)mark can be
;;; invoked without C-w). To disable these quick key strokes, set
;;; the variable win:quick-selection to `nil' in your ~/.emacs.
(autoload 'save-current-configuration "revive" "Save status" t)
(autoload 'resume "revive" "Resume Emacs" t)
(autoload 'wipe "revive" "Wipe Emacs" t)
(define-key ctl-x-map "S" 'save-current-configuration)
(define-key ctl-x-map "F" 'resume)
(define-key ctl-x-map "K" 'wipe)
;;;
;;;[How to use]
;;;
;;; Call `save-current-configuration' (`C-x S' if you define key as
;;; above) when you want to save current editing status and call
;;; `resume' to restore it. Numerical prefix arg to them specifies
;;; the buffer number in which the editing status will be saved.
;;; Here the buffer refers to a revive s-exp in ~/.revive.el of
;;; which there can be n
;;;
;;; [Sample Operations]
;;; C-u 2 C-x S ;save status into the buffer #2
;;; C-u 3 C-x F ;load status from the buffer #3
(setq revive:major-mode-command-alist-private
'(("*w3m*" . w3m)))
(setq w3m-session-load-last-sessions t)
desktop.el将对您的情况有所帮助。
它可以(从其介绍页面复制)从emacs包缓冲区中:
保存桌面,即, - 一些全局变量 - 带有关联文件的缓冲区列表。 对于每个缓冲区还有 - 主要模式 - 默认目录 - 点 - 标记和标记活动 - 缓冲区只读 - 一些本地变量
desktop-save-in-directory
),并通过desktop-read
函数读取它。 - Ehvince弹丸模式可以实现你想要的功能:
在一个项目内切换缓冲区:projectile-switch-to-buffer
切换项目:projectile-switch-to-project
我有类似这样的东西:
(global-set-key (kbd "C-x b") '(λ ()
(interactive)
(if (projectile-project-p)
(call-interactively 'projectile-switch-to-buffer)
(call-interactively 'ivy-switch-buffer))))
(global-set-key (kbd "C-x B") 'ivy-switch-buffer)