Adding a Journal Entry Using Org-Mode
Last week I decided to begin keeping a journal to record my programming notes and code snippets. Since I’m a dedicated emacs user I wanted to be able to maintain the journal without leaving emacs.
Some quick research led me to Org-mode. From the Org-mode homepage:
Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing project planning with a fast and effective plain-text system.
Clearly it is a powerful system, and has lots of features beyond those I need for a simple journal. However I was easily able to set it up to do what I need — namely, prepend date-stamped entries to a single file.
To make entering new journal entries as simple as possible I wrote the following function:
(setq journal-file "~/journal.org") (defun start-journal-entry () "Start a new journal entry." (interactive) (find-file journal-file) (goto-char (point-min)) (org-insert-heading) (org-insert-time-stamp (current-time) t) (open-line 2) (insert " ")) (global-set-key (kbd "C-c j") 'start-journal-entry)
It opens the journal file, creates a new date-stamped entry at the top, and then positions the cursor ready for me to type the body.
So now I can easily start a new journal entry at any time by hitting C-c j
.
Update: Dmitri Minaev pointed out that this can be more easily achieved by taking advantage of org-mode’s integration with remember-mode. Hence, I’ve replaced the above code with
(org-remember-insinuate) (setq org-remember-templates '(("Journal" ?j "* %U %? %^g\n\n %x" "~/Archive/journal.org" 'top))) (global-set-key (kbd "C-c j") 'org-remember)
The only thing I don’t like about this method is that trailing newlines are removed from the entry when it’s saved to the journal file. I prefer to separate journal entries by two blank lines. A quick check of the manual and the org-mode code didn’t uncover a way to turn off this behaviour.
Explore posts in the same categories: Uncategorized
20 December, 2008 at 3:37 AM
You might have missed the chapter on integration with remember-mode when reading the manual. Check it out, it’s worth it.
23 December, 2008 at 9:44 AM
Dmitri, thanks for the tip. I’ll definitely check out remember-mode in the manual.
10 February, 2013 at 11:12 PM
Thanks for the code – I am using your version, Dmitris version works in a way i dont like or understand! Yours is nice and simple and easy to understand