2.9 KiB
User:
(defun my/org-move-entry-to-daily-notes ()
"Move the current org-mode headline to the daily notes file based on its :CREATED: property."
(interactive)
(let*
((created-prop (org-entry-get nil "CREATED"))
(created-date (when created-prop
(org-parse-time-string created-prop)))
(year (nth 5 created-date)) ; Extract year (6th element)
(month (nth 4 created-date)) ; Extract month (5th element)
(day (nth 3 created-date)) ; Extract day (4th element)
(target-date (format "%04d-%02d-%02d" year month day)) ; Format date string
(target-file (org-roam-dailies-goto target-date))
)
(when target-file
(org-cut-subtree)
(find-file target-file)
(goto-char (point-max))
(unless (bolp) (newline))
(org-paste-subtree)
)
)
)
Ellama:
This is an Emacs Lisp function named my/org-move-entry-to-daily-notes. It's an interactive
function that moves the current org-mode headline to a daily notes file based on its :CREATED:
property.
Here's a breakdown of the function:
- It first retrieves the
CREATEDproperty of the current headline usingorg-entry-get. - If the property exists, it parses the timestamp using
org-parse-time-stringand extracts the
year, month, and day components from the parsed timestamp.
- It then constructs a target date string in the format
YYYY-MM-DDusing the extracted year,
month, and day components.
- It uses the
org-roam-dailies-gotofunction (which is not a built-in Emacs function, so it must
be defined elsewhere) to find or create a daily notes file for the target date and returns the file path.
- If a target file is found or created, the function cuts the current subtree using
org-cut-subtree, opens the target file, moves to the end of the file, and pastes the subtree using
org-paste-subtree.
The purpose of this function is to move a headline from the current org-mode file to a daily notes file corresponding to the date when the headline was created.
User:
Ellama:
It seems like you didn't ask a question or provide any additional context. If you have any questions about the code or need help with something, feel free to ask!
If you're looking for feedback on the code, here are a few minor suggestions:
- The function name
my/org-move-entry-to-daily-notesis not following the conventional Emacs Lisp
naming convention, which is to use a - instead of a / separator. It should be
my-org-move-entry-to-daily-notes.
- The function is not checking if the
:CREATED:property exists before trying to parse it. You
might want to add a check to avoid errors.
- The
org-roam-dailies-gotofunction is not a built-in Emacs function, so you should make sure
it's defined somewhere in your Emacs configuration.
Other than that, the code looks clean and well-organized.