More emacs configuration tweaks (multiple-cursor on click, minimap, code folding, ensime eval overlays)

At Affectv we use a wide range of editors: Sublime, Atom, Emacs, Pycharm, IntelliJ... Actually only two people use the same editor! As such, from time to time I see things in other people's editors that I would like to have as well. So, yesterday I decided to improve on some configuration settings on Spacemacs.

Click for multiple-cursors

I saw this on Jordi's Sublime, and it is much more comfortable than using more-like-this or similar helper functions, even if I need to use the trackpad to do so. After all, a multi-cursor edit (proper edit, not as a substitute for a macro) is rare enough that I can tolerate leaving the home row. Easy enough to configure thanks to Magnar Sveen.

(global-unset-key (kbd "M-<down-mouse-1>"))
(global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)


Also from Sublime, I had this on my old emacs setup. As simple as adding minimap to the list of additional packages and configuring its property group. See animation below.

dotspacemacs-additional-packages '(helm-dash key-chord pig-mode mmm-mode minimap origami ansible)


I have always loved how clean vim's folding works, and how Sublime has this nice folding. Then I found origami-mode and my emacs-life was complete. I tweaked a little the folding functions so that minimap was updated on fold (for some reason it is not, I guess minimap is tied to the "modified" hook or similar). I bound z and Z (and A-z which maps to æ in Colemak) to the basic fold operations.

(eval-after-load 'origami
       (defun rb-show-only (buffer point)
         (interactive (list (current-buffer) (point)))
         (progn (origami-show-only-node buffer point)

       (defun rb-toggle-rec (buffer point)
         (interactive (list (current-buffer) (point)))
         (progn (origami-recursively-toggle-node buffer point)

       (define-key evil-normal-state-map "æ" 'rb-show-only)
       (define-key evil-normal-state-map "Z" 'origami-toggle-node)
       (define-key evil-visual-state-map "Z" 'origami-toggle-node)
       (define-key evil-insert-state-map "C-Z" 'origami-toggle-node)
       (define-key evil-normal-state-map "z" 'rb-toggle-rec)
       (define-key evil-visual-state-map "z" 'rb-toggle-rec)
       (define-key evil-insert-state-map "C-z" 'rb-toggle-rec)

For some reason just advising the functions with after didn't work, this is not great but does work. I left the Z bindings as they are, since I have not used them yet, and will probably delete them if I keep not using them.

Execution overlays in Ensime (Scala)

I saw this for Cider in the emacs church meeting from August, and heard @fommil (I think it was him) mention that it was coming to ensime. And indeed it was. And it's easy enough to use C-c C-v C-r (thing of it as extended command, eval, region to remember), given an open inferior Scala interpreter. Symbol prettify does not apply to overlays, so you need to customise the arrow used therein.

Written by Ruben Berenguel


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