1

I was wondering if anyone has been able to use org-journal and create a second independent journal. Note that I use Spacemacs. I have been using org-journal for my daily journal, which is great. However, I want to create a second weekly journal to plan things out for the week. Right now org-journal bounds to C-j-j key, so I would like to have a different key combo that would open the second journal.

I was looking over the org-journal code. It looks simple enough, but was not sure if I was on the right track. If anyone can suggest a simpler way, that would be great. The original org-journal code is linked for reference.

The code for the location of journal files is. Below. So I would just have to create a second similar entry.

The first thing is to create a new keybinding:

 ;; Key bindings
 (define-key org-journal-mode-map (kbd "C-c C-f") 'org-journal-open-  
 next-entry)
 (define-key org-journal-mode-map (kbd "C-c C-b") 'org-journal-open-
 previous-entry)
 (define-key org-journal-mode-map (kbd "C-c C-j") 'org-journal-new-
 entry)

Then I need to add a new location to the org-journal-dir variable to set a new directory for the second journal.

 (defcustom org-journal-dir "~/Documents/journal/"
 "Directory containing journal entries.
  Setting this will update auto-mode-alist using
 `(org-journal-update-auto-mode-alist)`"
 :type 'string :group 'org-journal
 :set (lambda (symbol value)
     (set-default symbol value)
     (org-journal-update-auto-mode-alist)))

The function for creating a new entry is below. But the variable for the journal directory is saved in the org-journal-dir variable. So it is not an argument for the function below. Hence I would just need to copy this function and reference the name of the second variable created for org-journal-dir2.

 (defun org-journal-new-entry (prefix &optional time)
 "Open today's journal file and start a new entry.
 Giving the command a prefix arg will just open a today's file,
 without adding an entry. If given a time, create an entry for
 the time's day."
(interactive "P")
(org-journal-dir-check-or-create)
(let* ((entry-path (org-journal-get-entry-path time))
     (should-add-entry-p (not prefix)))

;; open journal file
(funcall org-journal-find-file entry-path)
(org-journal-decrypt)
(goto-char (point-max))
(let ((unsaved (buffer-modified-p))
      (new-file-p (equal (point-max) 1)))

  ;; empty file? Add a date timestamp
  (when new-file-p
    (insert org-journal-date-prefix
            (format-time-string org-journal-date-format time)))

  ;; add crypt tag if encryption is enabled and tag is not present
  (when org-journal-enable-encryption
    (goto-char (point-min))
    (unless (member org-crypt-tag-matcher (org-get-tags))
      (org-set-tags-to org-crypt-tag-matcher))
    (goto-char (point-max)))

  ;; move TODOs from previous day here
  (when (and new-file-p org-journal-carryover-items)
    (save-excursion (org-journal-carryover)))

  ;; skip adding entry if a prefix is given
  (when should-add-entry-p
    (unless (eq (current-column) 0) (insert "\n"))
    (insert "\n" org-journal-time-prefix
            (if (= (time-to-days (current-time)) (time-to-days time))
                (format-time-string org-journal-time-format)
              "")))

  ;; switch to the outline, hide subtrees
  (org-journal-mode)
  (if (and org-journal-hide-entries-p (org-journal-time-entry-level))
      (hide-sublevels (org-journal-time-entry-level))
    (show-all))

  ;; open the recent entry when the prefix is given
  (if should-add-entry-p
    (show-entry))

  (set-buffer-modified-p unsaved))))

The rest would seem to stay the same. Does this seem like the right way to do this, or is there a simpler way?

  • Instead of copying code, consider defcustom'ing something like journal-dir-alist, and implementing an interactive function which maps its invocation to a value therein (or prompts for a journal to open). Then, in that function, you can leverage Emacs Lisp's dynamic scope to let-bind journal-dir and call journal-new-entry, which will have the same effect as if you'd manually set journal-dir to a new value and made the call yourself - but doesn't require you to manually manage that state. – Aaron Miller Aug 16 '16 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.