Domanda

By workspace, I mean - I need to save the state of my open buffers (possibly in a user specified workspace file) and quickly switch to another set of open buffers, e.g. to continue working on files related to another project.

Is there an Emacs plugin which allows this? Which one would you recommend?

È stato utile?

Soluzione

I use a combination of save-visited-files and workgroups. In fact, workgroups will probably do most of what you want by itself.

My config:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 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))

Altri suggerimenti

Personally, I've been using `persp-mode':

Perspectives for emacs, based on perspective-el by Nathan Weizenbaum. But perspectives shared among frames + ability to save/restore from/to file.

desktop.el will be helpful in your situation.

It can (copied from its introduction page) from the emacs packages buffer:

Save the Desktop, i.e., - some global variables - the list of buffers with associated files. For each buffer also - the major mode - the default directory - the point - the mark & mark-active - buffer-read-only - some local variables

If you are using Linux/Gnome3, you can try this extension: https://extensions.gnome.org/extension/361/emacs-manager/ This extension will allow you to work on different projects simultaneously by managing multiple emacs daemons, and save/restore state of buffers.

HIROSE Yuuji's revive.el has worked nicely for me for quite some time. I use the standard configuration presented in the comments in revive.el. The documentation is well written and revive is very easy to use and configure. In particular, revive.el has better support than some for reviving configurations that are a bit more complex. It is particularly nice if you combine it with the HIROSE Yuuji's windows.el. They are made to work together. windows.el makes it possible to recall window splits, etc. revive.el is built with an eye toward extensibility toward deeper mode integration for particular setups. But for my uses, I have found it to be quite nice out of the box, though I think I'll next tweak it to revive w3m windows which I currently don't have setup (Update: I do now: see bottom).

Here is my revive config. I include some helpful comments, first for windows.el and then revive.el inline:

(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

There are variants of this that others like revive-plus.el and a slightly modified clone on github, but I prefer the original.

Update Monday, January 12, 2015: Now I can restore w3m in revive (see revive.el docs for details and in particular look at examples in revive:major-mode-command-alist-default):

(setq revive:major-mode-command-alist-private
      '(("*w3m*"    . w3m)))

Notice you are telling revive the name of the w3m buffer. Even if you have multiple tabs, only the first one need be enumerated as above.

Here is the w3m variable I have set to restore all tabs from the previous session:

(setq w3m-session-load-last-sessions t)

projectile mode may achieve what you what:

To switch buffers within a project: projectile-switch-to-buffer

To switch projects: projectile-switch-to-project

I have something like this:

(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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top