This is probably simple and I've been trying to develop some lisp skills but I'm completely stumped.

What I'm trying to do is insert a link in one file every time a TODO state change occurs (probably not necessary, but you can see more details in my older Stackoverflow post). The goal is to create an index of my activities throughout the day that all link back to my agenda file. E.g.:

[2014-09-03 Wed 09:05] - STARTED this is my heading
[2014-09-03 Wed 09:34] - DONE this is my heading
[2014-09-03 Wed 09:50] - STARTED this is another task in my agenda

I tried this:

(defun andy/journal-state-change (plist-chg)
  "When the state changes, link it into the journal"
    (org-journal-add-entry (plist-get plist-chg :position))

(add-hook 'org-trigger-hook

Which, according to the org-trigger-hook documentation will be give a property list which includes a :position property.

I modified the org-journal library to integrate this function into its journaling (snipped down for brevity):

(defun org-journal-add-entry (apoint)
  "APJ 5/4/15 add call for inserting from todo state change"
  ;; code snipped here which prepares this buffer to get the new
  ;; journal entry
  ;; my additions here:
      (org-insert-link (org-entry-get apoint "LOCATION") (org-entry-get apoint "DESCRIPTION") (org-entry-get apoint "DESCRIPTION") )
      (set-buffer-modified-p unsaved)

I'm pretty sure that's not the way to do it because I'm dealing with a point and trying to insert a link. It would be nice to just pass the TODO entry from the original but I'm not sure either how to get the link or to insert it in the other file.

Any suggestions greatly welcomed!

  • 1
    What does log mode in the agenda (press l) not give you. Commented May 6, 2015 at 6:44
  • That is awesome, I didn't know about that! It is a lot like what I want but the journal incorporated with this index that I'm trying to do would give me a daily record of the same sort. I imagine the log is sort of temporal, you get the reporting but depending on when you run it it would be different. Besides, it's the most I've done with lisp to date so I'm hoping to find a way even if ultimately the agenda log is cleaner.
    – AndyJ
    Commented May 6, 2015 at 15:58
  • See Exporting agenda views in the org manual if you wish to save particular outputs. Commented May 7, 2015 at 10:20

1 Answer 1


This is what I used to get the information I needed from the hook:

(defun andy/journal-state-change (plist-chg)
  "When the state changes, link it into the journal"

  (let* ((element (org-element-at-point))
         (heading (org-element-property :title element))
         (fromprop (plist-get plist-chg :from))
         (toprop (plist-get plist-chg :to))
         (jentry (format "%s (%s)" heading toprop))
    (org-journal-add-entry  (buffer-file-name) jentry)))

And then I inserted it using:

(defun org-journal-add-entry (fname entry)
  (insert (org-make-link-string (format "file:%s" fname) entry))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.