I want to thank you all for your help so far. I am slowly working the kinks out of my workflow. I know this isn’t org-roam strictly, but I can’t find an answer online and it pertains only to my roam buffers.
In my capture and capture-ref templates I have a field #+LAST_MODIFIED: that inserts the time. I’d like it to update every time the file is saved after that to represent its last save.
I got this from someone else’s org-roam setup, but I don’t remember where. How would I setup emacs to update that line at save? I think I am on the right path with time-stamp but I’m not sure how to call it. Here is what I have so far:
(setq
time-stamp-active t ; do enable time-stamps
time-stamp-pattern "5/#+LAST_MODIFIED: [%04y-%02m-%02d %a %02H:%02M]"
time-stamp-format "%04y-%02m-%02d %a %02H:%02M") ; date format
Would this work with my capture template below? (See also the example file below.)
Here is the relevant capture template:
#+TITLE: covenant as kinship
#+CREATED: [2020-06-05 Fri 12:34]
#+LAST_MODIFIED: [2020-06-05 Fri 12:34]
- tags :: [[footcite:hahn09:_kinsh_coven][p. 28-9.]]
Bilateral covenants per Cross, Glueck, smith, FRymer-Kenski are
kinship-oriented. That is they extend kinship rights and
responsibilities to another party. This kinship relationship is made
via a [[file:covenantal_oath.org][covenantal oath]].
Thank you! That is exactly what I needed. I can’t claim to weigh in on whether or not it should ship with org-roam. I am quite happy to have this in my config file(s). It is doing exactly what I want it to do.
I would love to implement this in my configuration.
I use spacemacs, and I do not use use-package to load my layers.
Could you point me to how I can use this hook?
I think that I can simply put all the definitions of the functions in my config file.
But how should I introduce the before-save hook in you 2590 line?
I added this part to my user-config in the init.el file.
(for spacemacs users that have their configuration in a .spacemacs file it should be in the user-config part of .spacemacs)
(add-hook 'before-save-hook #'zp/org-set-last-modified)
(defun zp/org-find-time-file-property (property &optional anywhere)
"Return the position of the time file PROPERTY if it exists.
When ANYWHERE is non-nil, search beyond the preamble."
(save-excursion
(goto-char (point-min))
(let ((first-heading
(save-excursion
(re-search-forward org-outline-regexp-bol nil t))))
(when (re-search-forward (format "^#\\+%s:" property)
(if anywhere nil first-heading)
t)
(point)))))
(defun zp/org-has-time-file-property-p (property &optional anywhere)
"Return the position of time file PROPERTY if it is defined.
As a special case, return -1 if the time file PROPERTY exists but
is not defined."
(when-let ((pos (zp/org-find-time-file-property property anywhere)))
(save-excursion
(goto-char pos)
(if (and (looking-at-p " ")
(progn (forward-char)
(org-at-timestamp-p 'lax)))
pos
-1))))
(defun zp/org-set-time-file-property (property &optional anywhere pos)
"Set the time file PROPERTY in the preamble.
When ANYWHERE is non-nil, search beyond the preamble.
If the position of the file PROPERTY has already been computed,
it can be passed in POS."
(when-let ((pos (or pos
(zp/org-find-time-file-property property))))
(save-excursion
(goto-char pos)
(if (looking-at-p " ")
(forward-char)
(insert " "))
(delete-region (point) (line-end-position))
(let* ((now (format-time-string "[%Y-%m-%d %a %H:%M]")))
(insert now)))))
(defun zp/org-set-last-modified ()
"Update the LAST_MODIFIED file property in the preamble."
(when (derived-mode-p 'org-mode)
(zp/org-set-time-file-property "LAST_MODIFIED")))
Is #+LAST_MODIFIED recognized by some other functions? I have tried to make time-stamp use the standard Org-mode #+date (I like lower case) keyword and only run it for Org mode files but I am not sure if #+date is allowed to have time.
I just watched your tutorials, thanks for making them!
One of the first things I noticed was the LAST_MODIFIED property in your file headers, and immediately searched out your config to steal your code. I’ve wanted this for a long time, so thank you.