I have a function I wrote that edits a file's PROPERTIES drawer on save and, if it finds the "MODIFIED" field it updates it with the current time. This works great as long as the drawer is open, but if the drawer is closed (the default state of a drawer on a newly opened file) than it deletes all parts of the drawer below the "MODIFIED" field.
This is my function
(defun 0x44/update-org-modified-property ()
"If a file contains a '#+MODIFED property update it to contain
the current date/time"
(interactive)
(save-excursion
(widen)
(goto-char (point-min))
(when (re-search-forward "^:MODIFIED:" (point-max) t)
(progn
(kill-line)
(insert (format-time-string " <%Y-%m-%d %a %H:%M>"))))))
And I just use add-hook
to add it to before-save-hook
.
How can I edit the values in a closed drawer? When a drawer is closed it seems that the concept of "lines" goes out the window and everything shares a single line. Thus, when I go to a point and run (kill-line) it kills everything after that point, which includes everything in the drawer below that specific k/v pair.
(kill-line)
it kills everything after that point, which includes everything in the drawer below that specific k/v pair.