Journalling in Emacs Org mode
Evil mode is great for Vi-lovers
Journalling in Emacs Org mode
I was looking for a solution to log some activities, together with a date and time indication. This could probably be done with the diary function of vimwiki, but I thought this was a good opportunity to try Org mode.
I have been using Vi en Vim for about two decades, so most keybindings have become part of my nervous system. Vi is extremely powerful and efficient but it takes some time to learn. When mustle memory kicks in, nothing can beat the power of vi.
Vi is a brilliant piece of software for which we should all worship Bill Joy.
Bram Moolenaar created Vim and with this took vi to a new level altogether.
After reading a lot about Evil mode on various webpages and watching the youtube video of Aaron bieber I thought Evil mode would smooth the transition to Emacs, without loosing too much of the power of vi and the mustle memory that has grown into me.
So, this page is about my new adventure into using Emacs.
Org mode is the real lure into Emacs. In the past, I have read a lot of the work from Sacha Shua and other sources about Org mode. There has been attempts to get the same functionality in Vim, but none beats Org mode.
Org mode journal
Org mode journal is a great way to log activities. In the default setup it creates a file for each day. Every entry starts with a header containing the time of the entry. If you create several entries on the same day, these entries end up in the same file, each of these entries will have it's own header, containing the time of the entry.
Because it is Emacs, this is only the standard, default method and it is easy to change this into something completely different, like having a journal file for each month. or put each entry into it's own file. It is all up to you.
Centralized solution, workstation independent
I don't want to store my journals on my workstation. There are several reasons for this.
- I use several workstations, like a Debian laptop, a Chromebook, and at work an OS X laptop
- Sensitive data does not belong on a laptop
- Important data does not belong on machines without automated backups
So I wanted my journals on a central machine. I choosed to put it on one of my OpenBSD servers. I can ssh into this machine from any of my workstations. attach to tmux and start working.
Problem in xterm with Alt key over ssh
I had some difficulties getting the Alt key to work over ssh. This was also a problem when I did ssh to localhost, so the cause was clearly on the sending end and not on the receiving end.
After playing around, I discoverd that the problem did occur when I start ssh from an xterm terminal, but did not occur when I start ssh from a rxvt terminal. So I had to do with the XTerm config on my Debian laptop.
I added this to .Xdefaults:
With this single line in place, everything works OK.
My .Xdefaults file gets xrdb merged by my .xinitrc, which starts the ratpoison windowmanager.
It seems like everybody who is actually working with Evil mode and Org mode has zillions of lines in their .emacs file.
I have always tried to keep my dotfiles small and the last years I have tried to remove as much as possible from my .vimrc file.
Starting with Evil mode and Org mode require a lot of lines in your .emacs. This is what I came up with, just to be able to use Evil mode, Org mode and to create a log entry.
(require 'package) (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/")) (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/")) (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/")) (setq package-enable-at-startup nil) (package-initialize) (defun ensure-package-installed (&rest packages) "Assure every package is installed, ask for installation if it's not. Return a list of installed packages or nil for every skipped package." (mapcar (lambda (package) (if (package-installed-p package) nil (if (y-or-n-p (format "Package %s is missing. Install it? " package)) (package-install package) package))) packages)) ;; Make sure to have downloaded archive description. (or (file-exists-p package-user-dir) (package-refresh-contents)) ;; Activate installed packages (package-initialize) ;; Assuming you wish to install "iedit" and "magit" (ensure-package-installed 'evil 'evil-leader 'evil-org 'helm 'org) (require 'org) (setq org-default-notes-file ".org/notes.org") (setq org-log-done t) (setq org-todo-keywords '((sequence "TODO" "|" "DONE" "CANCELLED"))) (setq org-journal-dir "~/.journal/") (setq org-journal-file-format "%Y-%m-%d.org") (defvar org-journal-date-format "%A %d-%m-%Y" "Date format string for journal headings.") (helm-mode 1) (require 'evil) (evil-mode t)
In this config I have added a few lines to get a better format for the dates (European format). Also, it gives the journal files the .org extension, so Emacs knows it has to go into org mode when reading these files (perhaps there is a better solution for this, but it works [TM]).
Also, this config puts the journals in the directory .journal.
This config also set some values for the TODO field in the Org mode TODO cycle and defines the place where to put the Org mode notes. I have not made much use of the Org mode todo and scedule management yet.
Adding log entries in the journal
Fire up Emacs and enter Ctrl-c Ctrl-j. This will open a new window with the date followed by a few points (elipses in LaTeX speak).
The text you enter immediately after these points will be part of the header of your entry, together with the current time.
The text you put on the line(s) below it, will become the body of your entry.
Save your entry with :wq.
After Ctrl-c Ctrl-j, but before start typing
After some annotations, before :wq.
Retreiving journal entries
I have found the following to be an easy way to get access to your entries.
Open the Emacs calendar with:
Walk to the day of the journal you want to see, by using the famous h,j,k,l key-bindings.
On the preferred day, hit Clrl-j.
A new window will be opened, with your entry in it.
Within Evil mode, you can switch to a window with the normal vim Ctrl-W key combinations, like Ctrl-W Ctrl-W.
Important data needs to be protected by automated backups. In my home network, every night a backup of my Git repositories is made.
What I did to protect my journals is setup a cron script that automaticly commits the .journal directory every night. This not only gives the protection of a seperate copy in my git repository and a backup of that repository, but also the benefits of having a versioning system.
Start of a new journey
This is my first step into discovering and using Emacs, and I guess it will be the start of a new and fruitful journey into using Emacs, using Org mode and using Evil mode.