home blog tags about

My start to Emacs/Spacemacs

written by Robin Schubert on 2017-08-30 | Tags: miscellaneous, wiki

Here I'm going to share my experience with Spacemacs - a GNU Emacs configuration - and how it became my main editor from the first start. I will try to mention all those little things that I found convenient but had to discover myself, as I could not find them in a comprehensive guide.

My personal editor history

I have always been a vim guy. I was taught vim during my Physics and Computer science studies, meaning: I had to learn it to pass the course, we even had weekly exams. I'm glad we did though, it's a great editor and once I got used to the keybindings (I still figure out some cool tricks every other day) I never wanted to use anything else anymore - and no mouse of course.

I use that keybindings everywhere I can, in my i3 environment, in my mutt email client, or when browsing with Palemoon and the Pentadactyl plugin.

In larger coding projects, some functionality has to be added to vim though (for my taste), to make the editor more convenient and to solve simple and repeating tasks quicker. I found vim to become quite slow when packed with too many plugins, especially with Python auto-completion / introspection it was no fun to use anymore.

So I switched to sublime text, an excellent editor in my opinion - providing vim mode e.g. with the vintageous package, hackable with Python code and very much customizable with json style settings. I loved it and still would use it, if only there wasn't this little sting all the time; Although free to use, Sublime text will remind you every X times you save your work, that you can buy a license (which is not even very expensive, 70$ for a superb product). This gave me a little stitch, not because good software has a price, but because it reminded me that I was using non-free software again. So I decided to give GNU Emacs another try.

I had installed Emacs on my system before to check out what's so nifty about it, that you would use it in favor of vim. I worked through the tutorial and I recommend to everyone doing the same. You will find Emacs keybindings useful everywhere - for example the Bash can be fully navigated using Emacs keybindings. However, the permanent use of the Ctrl and Alt/Meta key felt so inconvenient for me as vim user, not even evil mode could help it, and I abandoned Emacs.

I learned about Spacemacs in a #dgplug session and gave that a try. I was skeptic at first, but it turned out that Spacemacs felt so intuitive and convenient from the first use, that I stopped using any other editor in an instant.

Spacemacs

Spacemacs is just a configuration for Emacs. That was important to me, I did not want to loose compatibility to other Emacs set-ups and enjoy the full Emacs experience. Also I would be lost if I couldn't google for solutions to problems in classic Emacs forums.

However, the layer of abstraction that Spacemacs adds to Emacs is obvious. In Emacs, you can add features by adding a major mode and various minor modes to your buffer, and design a specific environment for all your specific tasks. That's either copy and paste someone else's config file to your own, or quite some time of fiddling with lisp.

Spacemacs does this by providing configuration layers, that will set up the major and minor modes and other things in the background for you already. So far I find this very convenient with nothing to miss for a nice workflow, no matter if I do Python coding, R scripting or writing my blogs or ToDos.

First things first

Installation was quite straight forward, following the steps on the Github page. I use Spacemacs with the helm (fully featured) distribution in evil mode (you will be asked for your preferences during first start-up).

I updated my configuration layers by editing the config file: space f e d for file -> emacs -> dotfile I commented in all of the configuration layers that were out-commented per default, like autocompletion better-defaults git markdown and org etc. and added some others for my daily work: python, django, latex, ess (which is the R layer).

Although I added some snippets to my config file, I did not change the default behavior or keybindings, so everything I write here refers to default settings.

Basic usage

Spacemacs commands mainly can be triggered using the Space key. A menu will pop up with keys and descriptions of options you have next. File operations, for example, can be accessed with f, so space f will lead you to another menu with options on file procedures. Another f press will let you open a file. Again it is useful to have at least a little Emacs background knowledge, so find file will sound familiar to you and the space f f keybinding makes sense all of a sudden. This command opens a file on your disk. space f s will save your buffer to the file. It's so intuitive, your fingers will almost move by themselves.

Similarly, space g will bring up a git (magit) menu (the best interface to git I have ever seen, by the way), given you have activated the git configuration layer in your dotfile.

With the projectile mode, space p shows options related to projects - e.g. every folder that contains a .git folder is considered a project. space p f for project find file will trigger a fuzzy search on files all over that project folder and sub-folders. I loved the ctrl+shift+p keybinding in Sublime text, that just did that and was happy to find that feature implemented. space m shows the options of your currently activate major mode. In Python mode for example, it will provide me with options of jumping to definitions, open a REPL, execute code, etc. Since the major mode may be used quite frequently, you can just type , (comma) to abbreviate the space m (it sounds ridiculous but it's really nice to have).

In Emacs, you can assign keybindings to every function or macro of your choice. The keybindings change with the modes you activate, and of course they can be changed in your config files individually. To me, this seemed a bit chaotic and I was overwhelmed with the possibilities. I also found it difficult to remember many of those key combinations. You can however call every function by name (given that you know the name). Spacemacs let's you do the same thing, but by default lets you search for the desired function with a nifty fuzzy search. You can trigger that either with the original Emacs Alt x keybinding or by pressing space space. I do that very often for functions I don't need to remember the key combinations, because I don't use them too often. I use that for example to sync my org files with my caldav calendar. The command is called org-caldav-sync, I don't even know if I have assigned a shortcut. However, I press space space and type sync to execute the command. There is nothing that interrupts my workflow, I don't even have to think about it.

In general, Emacs provides an excellent help, if you know how to pull it up. You might already guess it, you will find all help related options with space h. Here you can choose e.g. space to learn about the Spacemacs specific options and configuration layers. But what's really cool is what you'll find under space h d (for help -> describe). Here you can find help on any function (f), mode (m), package (p) and many more. Particularly helpful: space h d b (help describe bindings) let's you fuzzy-type a function and shows you the keybindings to it. The other way round space h d k will let you type a keybinding to show you the documentation of the function it triggers.

Org mode

A comprehensive guide to org mode is by far beyond the scope of this blog post, but I wanted to mention this in particular, since it's something non-emacs users hardly ever get to know.

Org mode is something I read of before, but never really could make sense of. Maybe that's because it's so versatile. You can use it to organize your TODO lists, but you can as well use it to create beamer presentations, websites or to write a scientific article. The syntax is a structured text very similar to markdown or rST; similarly you can export your .org files to a variety of formats (latex/pdf or beamer, html - plain or even with twitter bootstrap css and js, open office odt and many others). Instead of just managing TODO items, you can have agendas, schedule tasks and record progress. Writing tables and formatting any kind of text is super easy. What I find a very cool bonus: raw org files on Github are rendered automatically to beautiful websites.

I started to use it for my tasks at work but also for my private appointments as well. The , to trigger the major mode commands comes very handy again.

You can create items with a simple asterisks. shift right/left will let you cycle through the todo sequence, so you can mark an item as TODO or DONE ect. You can nest items in a tree structure with more asterisks, give them tags and define deadlines or schedule your tasks. To schedule you simply press , s, which will bring up a calendar to choose from. The interface is smart enough, however, to recognize most notations you type. To schedule the task for the next day, you could write +1, to put it on next Monday just type Monday (or even just mon) and hit enter. Type 1 sep if you want to schedule for September 1st. Same thing applies for deadlines , d. For many key combinations, I don't even know whether they exist. I just try what comes to my mind and Spacemacs reads my thoughts.

You can have an arbitrary number of org files with tasks and TODOs of different domains. I have one for work and one for private stuff. With ctrl+c [ you can bring an org file to your agenda (actually I haven't found a Spacemacs keybinding for that, yet). Your agenda can show you scheduled tasks and deadlines for the current week or provides other views and filters to not loose track. You can bring it up with , a a while in org mode (remember that , triggers major mode commands) or with space a o a (for apps -> org -> agenda) from any buffer and mode.

This blog is written in Org mode and transferred to Wordpress.com with the org2blog module. All I have to add are some meta information. This can be done using the #+ tag. #+TITLE: <my title here> will add a title to my blog post.

update: I moved the blog from wordpress to my own server, and write posts in markdown ever since. I use lektor to build the blog and lektor can read markdown natively.

elisp

Again, I cannot go into detail, describing lisp or emacs lisp (elisp) here. For those who don't know lisp, it's a quite old functional programming language, with a lot of parentheses. It's quite powerful, although I still find it hard to read. @shakthimaan gave an excellent starting point for elisp coding in a dgplug session.

If you use Emacs, I dare say you won't be able to avoid elisp completely, if you want to customize the editor a bit to your needs. Emacs itself is largely written in lisp and is fully hackable if you know that language. Using Spacemacs, you probably won't get in touch with elisp that often or intensively. If you want to add a configuration layer in the dotfile, you basically add an item to an elisp list, but you'll hardly notice. Still, I would recommend to everyone to dive into that language if you consider using Emacs or Spacemacs for you all-day work. Apart from the fact that it's a fascinating and historically important language, it will make your life easier if you know what you're doing. The basics (syntax, builtin datatypes and functions) are learned quite quickly; the real big deal is about learning the third party functions - I'm still too new to the language to be able to oversee the countless possibilities, but I will dive deeper into it some time.

Creative Commons License