Easily manage Emacs workspaces with eyebrowse

You know how many windows managers have workspaces you can switch between? These are variously called “virtual desktops” (e.g. KDE) or “spaces” on OS X, but the idea is the same; you have one workspace with a collection of windows/apps (say for mail and browsing) and another with the windows/apps for a particular project, and you can quickly switch between them. The eyebrowse packages gives a nice simple interface to the same experience in Emacs.

I install and configure eyebrowse with the following code in my emacs config file:

(use-package eyebrowse
  :diminish eyebrowse-mode
  :config (progn
            (define-key eyebrowse-mode-map (kbd "M-1") 'eyebrowse-switch-to-window-config-1)
            (define-key eyebrowse-mode-map (kbd "M-2") 'eyebrowse-switch-to-window-config-2)
            (define-key eyebrowse-mode-map (kbd "M-3") 'eyebrowse-switch-to-window-config-3)
            (define-key eyebrowse-mode-map (kbd "M-4") 'eyebrowse-switch-to-window-config-4)
            (eyebrowse-mode t)
            (setq eyebrowse-new-workspace t)))

The enables the shortcuts M-1 to M-4 to access 4 virtual desktops (N.B. you will have to disable the M- numeric prefixes first). Of course you can add more than 4 if you need to.

Now you will start by default in workspace 1. If you hit M-2 you will switch to a new empty workspace, numbered 2 in the modeline. It will initially just contain the scratch buffer, since we used (setq eyebrowse-new-workspace t). Open whichever buffers and window arrangements you like then hit M-1 to switch back to the first desktop where you will see the windows and buffers you had set up there.

A useful command is C-c C-w , (N.B. the comma is part of the command!) which runs eyebrowse-rename-window-config allowing you to name a workspace, and that name then appears in the modeline instead of the workspace number.

  • There is also “C-c C-w .” Which let’s you choose a workspace by number or name in the minibuffer.

  • Emacs Watcher

    I ended up using [[perspective|https://github.com/nex3/perspective-el]] for its projectile interface

  • If you want eyebrowse to start automatically at start up, add (eyebrowse-mode t) to the end of the use-package code above. Otherwise you’ll have to start it by hand.

    I also add the following keybindings for moving through all workspaces.

    (define-key eyebrowse-mode-map (kbd “H-“) ‘eyebrowse-next-window-config)

    (define-key eyebrowse-mode-map (kbd “H-“) ‘eyebrowse-prev-window-config)

    Setting the keybindings to something a little easier to type than C-c C-w and you’ll never know how you lived without it. I have remapped the right alt key to Hyper, so flipping between workspaces H-1 – H-6 is very fast and makes it easier to remember what is on which workspace.

    A student popped in my office this morning and I showed her a little demo of how to use magit and post-receive to deploy a website. I hit H-5 created a couple of windows and fired everything up, did the demo and after she left, I was able to hit H-3 and I was back in the same context I was in before the interruption. The two things that now help me minimize interruptions is eyebrowse and setting up org capture to popup in an external frame, choose a template, make a link, a bibtex, entry, todo item or notes from a phone call, hit C-C C-c and I’m back in my previous context!

    • Good suggestions – thanks! I somehow missed (eyebrowse-mode t) – fixed now!