Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide alternative to non-standard CREATED property #1053

Open
grothesque opened this issue Feb 23, 2024 · 2 comments
Open

Provide alternative to non-standard CREATED property #1053

grothesque opened this issue Feb 23, 2024 · 2 comments

Comments

@grothesque
Copy link

grothesque commented Feb 23, 2024

  • I have searched for existing issues that may be the same as or related to mine.

Orgzly defaults to creating a CREATED property for each new note.

As far as I can see the CREATED property is not standard. It is not listed among orgmode's special properties. The term CREATED does not even occur in Orgmode's source code.

I believe that the CREATED property convention might have been introduced by the org-expiry.el contributed package.

Orgzly's configuration allows to change the name of the property from CREATED to something else, but it must always be a property. This is not idiomatic in org, where the official documentation suggests simply using an inactive timestamp for saving the creation time of a note.

As far as I can see users who would like to follow this recommendation are unable to do so with Orgzly. It can be annoying to have to manually edit each note taken in Orgzly if one values a consistent format and one does not follow Orgzly's convention.

@nick4f42
Copy link

nick4f42 commented Apr 15, 2024

Just adding my two cents here, but I think a CREATED property is better than just including the timestamp in the headline contents.

  • You can do property searches based on the creation date, e.g. CREATED>="<2023-12-24>" (see Matching tags and properties).
  • You can see the creation date of multiple headlines using Column View.
  • You can extract the creation date in elisp with (org-entry-get (point) "CREATED").

There is the TIMESTAMP_IA special property which selects the first inactive timestamp, but it might not select the timestamp you want. For example, the timestamp in a note added with org-add-note is chosen first.

All that being said, I do think Orgzly should have an option to put the creation timestamp in the content for people who prefer it that way.

For anyone that wants to migrate to the CREATED property way, I'll share what I ended up doing. First, you can make sure new captured notes have the CREATED property with :hook in the capture template:

(defun my-org-entry-put-created ()
  "Add a CREATED property with the current date and time."
  (interactive nil org-mode)
  (let ((prop "CREATED"))
    (if (org-entry-get (point) prop)
        (user-error "%s property already exists" prop))
    (org-entry-put
     (point) prop
     (format-time-string (org-time-stamp-format 'with-time 'inactive)))))

(setopt org-capture-templates
        '(("t" "Task" entry
           (file "")
           "* TODO %?\n\n%i"
           :empty-lines 1
           :hook my-org-entry-put-created)
          ("n" "Note" entry
           (file "")
           "* %?\n%i"
           :empty-lines 1
           :hook my-org-entry-put-created)))

Then, to convert old headlines to the new format, you can use this command. Make sure to diff-buffer-with-file to check the changes before saving. Also be aware that it doesn't detect timestamps in headlines where a note was added with org-add-note when org-log-into-drawer was nil.

(defun my-org-propertize-timestamps (&optional property)
  "Convert beginning of content timestamps to properties."
  (interactive nil org-mode)
  (or property (setq property "CREATED"))
  (org-map-entries
   (lambda ()
     (let ((entry (point-marker)))
       (unless (org-entry-get entry property)
         (org-end-of-meta-data 'full)
         ;; When the first line of content is an org timestamp, convert
         ;; it to a property.
         (if (looking-at org-tsr-regexp-both)
             (atomic-change-group
               (let* ((beg (match-beginning 0))
                      (end (match-end 0))
                      (ts (delete-and-extract-region beg end)))
                 (when (eolp)
                   (delete-char 1))
                 (org-entry-put entry property ts)))))))))

@grothesque
Copy link
Author

Nick, thanks for your comment and the attached code.

Just adding my two cents here, but I think a CREATED property is better than just including the timestamp in the headline contents.

If you think that your arguments are strong enough, I suggest that you raise this issue on the org mailing list and try to make the CREATED property officially endorsed in some way.

Otherwise, Orgzly introduces an (arguably minor) incompatibility into the org-o-sphere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants