r/orgmode • • 10d ago

question What methods are there for checking when the content of an org headline or node was updated?

The places that come to mind readily are LOGBOOK timestamps and date values like the DEADLINE, CLOSED AND SCHEDULED values.

The only others I can think of are custom properties which are manually updated, eg an UPDATED-TIMESTAMP property.

Any others?

Is there an API for checking the

6 Upvotes

3 comments sorted by

2

u/mmarshall540 10d ago

LOGBOOK timestamps and date values like the DEADLINE, CLOSED AND SCHEDULED values.

Not sure if you are including this in the above, but pressing C-c C-z lets you add a "note" to a heading. It can either go in a LOGBOOK drawer or as a list item at the top of a heading's content and includes an inactive timestamp...

TIMESTAMP_IA property

Since it is placed immediately after the headline or properties drawer, you can use the TIMESTAMP_IA special property in a custom agenda-view to get a list of notes from the last 30 days or some other date range.

It's a manual approach, so you have to remember that your updates to an existing heading should go into this kind of note. Alternatively, you could just type C-c C-z C-c C-c to add the note and timestamp without any text.

So it doesn't automatically catch every single update the way that your filesystem's mtime would in a single-file-per-note type system (e.g. Denote or Org-roam). But I like it better this way. If I correct a minor typo in an old note, I don't necessarily want that to push the note to the top of my recent-notes list. Also, by preferring this top-note style of updating, it provides a better view of how my thoughts on a topic have changed over time.

Here's the entry in my org-agenda-custom-commands list for showing notes created or updated in the last 30 days.

("nM" "Updated/Created in last 30 days" tags
    "TIMESTAMP_IA>=\"<-30d>\"|CREATED>=\"<-30d>\""
    nil)

custom MODIFIED property (not recommended)

Before this, I would use a custom MODIFIED property. But I stopped using that because it was hard to maintain the code that sets it, and it would update the timestamps even when minor changes were made. Basically the code would calculate a hash for each heading in a file and compare it with the heading's existing HASH property. If they were different, it would update both the hash property and the timestamp stored in the MODIFIED property. This meant that any minor change to a note always updated the timestamp.

So I don't recommend trying to automate tracking of modification times. The built-in C-c C-z way work best for me.

custom CREATED property (recommended)

You may notice this in the custom agenda-view code above. This is something I saw the Orgzly-revived android app doing, so I added it to my Emacs config to match.

All it requires is some simple code that adds the property with a timestamp whenever a new note is created. It only adds the property upon note creation, so it's much easier to maintain and doesn't cause problems if some new package makes automated changes to your headings.

Here's the code I use to automatically add this property to new notes.

(defun my/org-add-created-property ()
  "Add a CREATED property in the same format used by Orgzly."
  (interactive)
  (when (and (eq major-mode 'org-mode)
             (not (org-entry-get (point) "CREATED")))
    (org-set-property
     "CREATED"
     (format-time-string (org-time-stamp-format t t)))))

(add-hook 'org-insert-heading-hook 'my/org-add-created-property)
(add-hook 'org-capture-before-finalize-hook 'my/org-add-created-property)

This adds the CREATED property when adding notes with M-RET, C-RET and org-capture. But it doesn't add the property if you just manually type a heading into your file with asterisks and a space at the beginning of a line. Didn't feel the need for that.

0

u/vfclists 10d ago edited 10d ago

It is as much I thought, as before this I had come to the conclusion that a custom command to update a custom property would be the way forward.

I guess rather than use a C-c C-z C-c C-c command sequence I must as well use a shorter one.

I think the modified function from ESE is the way forward, not on the whole file but on a per headline or node basis, or a much more direct one which updates a property directly.

Before this, I would use a custom MODIFIED property. But I stopped using that because it was hard to maintain the code that sets it, and it would update the timestamps even when minor changes were made

Is it because of changes Org's API over the years?

1

u/mmarshall540 9d ago

Is it because of changes Org's API over the years?

Not at all. I think when I actually decided to stop using the MODIFIED property was when I tried some package or custom code to add bi-directional links to notes. In order to prevent every note from having its MODIFIED property change when the back-link was added, I had to update the code that sets the HASH property to make sure it didn't look at the new back-link text.

New exceptions kept popping up, and each one had to be accounted for in the code. Eventually I decided it wasn't worth it to have this code that goes through my entire Org file on every save and makes automated changes. It made me nervous about making a mistake that loses data.

It was simpler to just get in the habit of updating notes with C-c C-z.