This weekend Neil Watson asked if I could share how I use org-mode with Spacemacs.
@cmdln_ Care to share with an Emacs illiterate how you got Spacemacs and Org-mode to work together? – @neil_h_watson
First of all, I spend most of my time in a terminal, and vim
is ingrained in
my muscle memory any time I need to edit a file. While Vim is my goto editor I
consider myself just a novice Vim
user. I like Vim because its everywhere and
I have grown to like modal editing. I am by no means an expert but I do use
visual block selection, and I like how Neil's great vim_cf3
plugin improves
the CFEngine policy editing experience tremendously.
So why are we talking about Emacs if Vim is go great? Note, we are talking about Spacemacs, which is self described as "community-driven Emacs distribution" and says "The best editor is neither Emacs nor Vim, it's Emacs and Vim!".
For me Org-mode is a (if not the) killer-feature in Emacs.
Org mode is for keeping notes, maintaining TODO lists, planning projects and authoring documents with a fast and effective plain text system. – http://orgmode.org/
I have used Org mode off on and on for the past 5 years or so, and mostly on for that past 2 years. When I first tried using org-mode I think one of the main reasons it didn't stick was because I didn't have familiar key bindings. I really struggled to navigate and operate within Emacs.
A couple years ago In order to be able to edit text inside Emacs I began
configuring Emacs to use Evil which made it possible for me to do things like
save and quite with :wq
and made most of the vim operations I was used to
using like visual region selection work pretty much as expected. I had
re-factored my Emacs config to try and make it more manageable about a year ago
to use use-package but for some reason Spacemacs escaped me until a couple
months ago. It wasn't too difficult to switch to Spacemacs I took most of my
custom config and dropped it into dotspacemacs/user-config
in ~/.spacemacs
.
Since I tend to have an org-mode buffer open all the time, getting org-mode configured to my liking was one of the first things I did.
I enabled the org layer.
|
|
I really like the dark solarized theme so I set soliarized-dark
to be the
first theme listed in dotspacemacs-themes
in dotspacemacs/init
.
|
|
Moving on to the rest of my org-mode configuration, the following blocks all
reside within dotspacemacs/user-config
.
|
|
In my notes I frequently link to tickets in zendesk, redmine, and jira so I made abbreviations for them. When viewing my org notes the links are functional hyperlinks that I can click on and importantly they work as expected when you export from org mode.
|
|
Here I specify the org files (or directories full of files as in my case) that should be used when working with the agenda. The agenda is neat, though I admit I have not trained myself to live in it yet. It allows you to search and display items throughout your org files. You can even interact with things directly from agenda views.
For example from anywhere in Spacemacs you can type SPC a o t
that's space a
for applications, o
for org, and t
for todos. This will list various entries
that begin with TODO (an entry is simply a line starting with one or more *
).
|
|
I have lots of org files. This just allows me to easily move entries from one file to another (re-filing).
|
|
Capturing new TODO items is really quick and unobtrusive with
capture templates. I have a capture template setup to for my TODOs. From any
buffer within Spacemacs I can type SPC C c t
to capture a new TODO entry. If I
happen to be editing an org-mode file I can type , c t
to start the capture.
This makes it incredibly easy to capture a TODO from anything I am working on.
I also try to keep track of the time I spend on various things, so you will notice that my TODO capture clocks my time while capturing, and when done it resumes the clock wherever I was clocking time before I started the TODO capture. Org makes it really easy to make clock tables so you can visualize and account for your own time. It even has support for effort estimates.
|
|
I picked this up from a co-worker. It automatically indents things in org-mode. I think it makes the experience with org-mode feel less like working in a free form text editor. Before I enabled this I was always trying to manually keep things aligned and it was sub-optimal.
|
|
Sometimes it's nice to be able to zoom in on some text. This simply maps the familiar keys for zooming.
|
|
I haven't yet mapped all the things I do frequently into shorter key sequences.
This binding allows me to type SPC o a
from anywhere in Spacemacs and get to
the main agenda dispatch where I search for entries based on tags or content.
|
|
Moving entries between files can wreck links between entries. So I have a hook to create unique ids for each captured entry. This way notes that link to TODOs shouldn't break.
|
|
My notes tend to include a lot of source code blocks. Here I allow sh blocks to
be directly executed by org-bable. That means I can type shell code between
#+BEGIN_SRC sh
and #+END_SRC
blocks and then press ,,
to execute it and
have the result inserted into its own section below the source. This is a really
nifty feature. It enables "Literate DevOps" as Howard Abrams calls it.
Seriously, go read and bookmark that page.
|
|
As you can guess I type a lot of cfengine code blocks. This defines an "easy
template" to inserting new cfengine blocks. I can simply type <cfe
followed by
TAB
.
|
|
Some of my notes have secret stuff, so here I set some things that allow me to encrypt entries.
|
|
In addition to those customization's I also use readtheorg html theme when exporting my notes. To make my note exports beautiful most of my org files have the following line at the top.
#+SETUPFILE: ~/src/org-html-themes/setup/theme-readtheorg.setup