Moving from Emacs to Spacemacs

A couple of days ago I attended (first time I managed in almost 6 months) the London chapter of the Emacs Church (also known as the local meetup for emacs lovers). In this event we were shown how to use emacs effectively for Clojure development (using Cider) and I saw in real life Spacemacs.

In case you don't know, Spacemacs is a "distribution" of Emacs prepared (is open source, of course) to be easy to setup, and somehow specially prepared for former Vim users to move to Emacs. For instance, on startup asks if you want to be in Emacs mode, evil mode or hybrid (Emacs mode keys in vim insert mode) by default.

As you may remember, I've been using Emacs with evil for around 3 years already, and have been pretty happy with it. I'm not so happy about the state of my .emacs file: currently it is 2652 lines long (of course around 400 or 500 of those are generated automatically by custom). Too big and unwieldy. And I'm too lazy to move all the nuts and bolts to something more lightweight and sane.

I thought that trying out Spacemacs could be the perfect excuse to clean the mess off my .emacs file, since I could carefully move piece by piece whatever I needed as I needed it (like I usually do when upgrading computers).

For a start, the beginning was a good experience. Since by default it includes most of the fancy stuff I use normally (helm being the biggest, fanciest helper I need, I only needed to tweak helm-files and switch-buffer, and add recentf) and I no longer use mu4e on a day-to-day basis, I could easily switch to it.

It's actually really easy to try Spacemacs alongside your normal emacs: just download it and from the spacemacs folder run something like
HOME=~/fromsource/spacemacs /Applications/Emacs.app/Contents/MacOS/Emacs
or the equivalent in your environment. Caveat: multi-term/ansi-term won't work as expected (best solution is to actually move to using Spacemacs as default). Aside from that I have had no other big issues, and recently moved to Spacemacs to be the main Emacs and if needed I can run my old configuration with the "HOME trick".

One thing I have not figured out how to exactly do "the Spacemacs way" but I needed no matter what is having my set of normal Emacs keybindings in evil insert and normal modes. Hybrid mode covers insert more or less nicely, but some commands I need them as they are because not only are they part of my muscle memory, but I also happen to like them and use them everywhere (OS X input fields, terminal windows). I tried to set this up in many places in the .spacemacs file (the user-config section, using the -init or -after macros of package initialisation...) And finally this made it work, so, in case you need to modify evil insert or normal key maps in Spacemacs:

(eval-after-load 'evil 
 (define-key evil-normal-state-map (kbd "SPC") 'ace-jump-mode)
 (define-key evil-insert-state-map (kbd "C-a") 'move-beginning-of-line)
 (define-key evil-insert-state-map (kbd "C-e") 'move-end-of-line)
 (define-key evil-insert-state-map (kbd "C-k") 'kill-line)
 (define-key evil-insert-state-map (kbd "C-w") 'kill-region)
 (define-key evil-visual-state-map (kbd "C-a") 'move-beginning-of-line)
 (define-key evil-visual-state-map (kbd "C-e") 'move-end-of-line)
 (define-key evil-normal-state-map (kbd "C-a") 'move-beginning-of-line)
 (define-key evil-normal-state-map (kbd "C-e") 'move-end-of-line)
 (define-key evil-normal-state-map (kbd "C-k") 'kill-line)
 (define-key evil-normal-state-map (kbd "C-y") 'yank)
 (define-key evil-insert-state-map (kbd "C-y") 'yank)
 (define-key evil-insert-state-map (kbd "C-t") 'transpose-chars)
 (define-key evil-normal-state-map (kbd "C-w") 'kill-region)
 (define-key evil-visual-state-map (kbd "C-w") 'kill-region)
 (define-key evil-visual-state-map (kbd "SPC") 'ace-jump-mode)))
Something I found surprising though is the load time: Spacemacs does not load packages on startup and my .emacs setup did, and they roughly start up at the same speed. Somehow I expected a faster startup time.

Worth also downloading the latest emacs port for homebrew, which fixes some annoyances with powerline colours as well as being quite more up to date than Carbon Emacs.

Now the only big thing left I have is reconfiguring multiple-cursors and my definitions of more-like-this and all that to be a happy Spacemacs user.
Written by Ruben Berenguel


Ruben Berenguel, PhD

Started a long time ago. It was supposed to be about a phenomenon leading to chaos: separatrix splitting. I got a research grant. I worked on holomorphic dynamics. Travelled. Presented. Too many roadblocks with the separatrix problem. Switched topics. Welcome to a different new world, infinite dimensional dynamical systems. I read the literature. Researched, proved some things. My grant ran out. I worked. A lot. Too many times I considered giving up. Kept thinking of the sunk cost fallacy. My advisor and my girlfriend helped me keep at it. I pushed on.

All this happened in early February, and since then many more things have happened. Right now I'm working part in London and part at home as a mix of software and data engineer, with a dash of devops to make it more spicy. Truly a jack of all trades (but I specially like the data science part).
Written by Ruben Berenguel


SyncTeX and pdf-view-mode for emacs

Or, destiny is cruel
Back in the days of yore, when I was switching between my Windows machine and a Linux machine, I remember having SyncTeX active in my Windows machine. It was a wonderful experience: SyncTeX lets you click anywhere on a generated file from LaTeX and gets back to your editor, to the place generating where you clicked. This was extremely useful, specially later on when you need to adjust many formulas to fit and you need a bit of back-and-forth-ing.

Then I got a Mac, and since Preview is so handy I slowly forgot about SyncTeX. Time went on, and I merrily kept on editing LaTeX files as usual. I even managed to deliver my PhD dissertation a couple weeks ago, the formal speech will be in a month or two (come at your own risk). AucTeX’s preview saved most of the days, so I slowly even forgot SyncTeX existed. Shame on me indeed.

The other day I got an annotated PDF from one of my advisors, and I just couldn’t open the annotations. I tried all programs I had for Mac, and no luck: annotations weren’t showing, just saw the icons. Surveying for some command-line tool to extract annotations (just in case) I found pdf-tools, a replacement for DocView based on Poppler. It had the awesome ability of actually displaying annotations, with it it was pretty clear the annotations were broken in that PDF. I got a new set of PDFs from my advisor with the annotations in place, though. While waiting for it to arrive…

I saw SyncTeX was an option of pdf-tools. I had been using that, hadn’t I? So, I activated SyncTeX in AucTeX (it is TeX-source-correlate-method, see here) and indeed: I could have two frames, one with the actual LaTeX sources and the other with a PDF, and go from one to the other. Even hyperreferences in PDF work! See (well, click on the full-screen mode to see it larger or you won't see anything)!

Getting pdf-tools to work wasn’t incredibly tricky (given the hoops you need for some packages, sometimes). Just

brew install pdf-tools

and after reading

brew info pdf-tools

I was told to run

  emacs -Q --batch --eval "(package-install-file \"/usr/local/Cellar/pdf-tools/0.60/pdf-tools-0.60.tar\")"

and this does the trick (well, change emacs for your actual emacs, which likely is /Applications/Emacs.app/Contents/MacOS/Emacs) You’ll also need to add to your .emacs file (or temporarily in your *scratch* buffer)

(setenv "PKG_CONFIG_PATH" (concat "/usr/local/Cellar/zlib/1.2.8/lib/pkgconfig" ":" "/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig"))
(getenv "PKG_CONFIG_PATH")

and run


as advised in the package’s README. And that's it, open a PDF and activate pdf-view-mode to check everything is in place. Well worth it!
Written by Ruben Berenguel