I’ve been keeping a journal for a couple of months now. I want to make it a habit to hone my writing skill. Taking notes of what happened on my day. I love my terminal and I’ve been used to take notes in plain text using either vim or emacs. So when I heard about jrnl, I decided to give it a try.
jrnl allows me to write a journal entry straight from cli. It will automatically tag the entry title
with a timestamp on when I log the journal. It also has encryption features and useful query
commands if I want to queries entries from a certain time range or having some tags. But in
practice, I usually just use it to write the entry title and continue editing with emacs. I keep my
journal text file with
.md extension so that my emacs markdown-mode kick in and highlight the
entry header, distinguishing it from the body. Everything went well until I upgrade my jrnl from v1
jrnl v1 is very relaxed in terms of date format. I made the entry date format to have single
the beginning so that markdown-mode will highlight the whole title line with h1 color. But jrnl v2
restrict the date part of the title line to be wrapped with square brackets, probably for simpler
parsing. It able to migrate my existing journal into the new format, but the new format is not
compatible with markdown, so the highlighting is gone.
I don’t want to lose the highlighting on my entry title. So I set off hacking my own jrnl highlighting in emacs. Some internet browsing later leads me to font lock mode and a tutorial on how to hack one.
The result is the following jrnl-mode.el
(defvar jrnl-mode-hook nil) (defconst jrnl-regex-header "\\(^\\[[^]]+?\\]\\) \\(.*$\\)" "Regex for jrnl entry header") (defconst jrnl-regex-tag "\\(\\W@\\w+\\)" "Regex for jrnl tag") (defconst jrnl-font-lock-keywords-1 (list (cons jrnl-regex-header '((1 font-lock-type-face t) (2 font-lock-variable-name-face t))) (cons jrnl-regex-tag font-lock-function-name-face) ) "Minimal highlighting expressions for jrnl-mode") (define-derived-mode jrnl-mode prog-mode "jrnl" "Mode for editing jrnl document." (setq font-lock-defaults '(jrnl-font-lock-keywords-1)))
I put this file as
~/.emacs.d/modes-el/jrnl-mode.el. To make emacs autoload it, I put this my
;; Load path etc. (setq dotfiles-dir (file-name-directory (or (buffer-file-name) load-file-name))) (add-to-list 'load-path (concat dotfiles-dir "/modes-el")) (autoload 'jrnl-mode "jrnl-mode.el" "..." t) ;; JRNL highlighting (add-to-list 'auto-mode-alist '("\\.jrnl$" . jrnl-mode))