Files
memex/ellama-sessions/Emacs Lisp (Open AI).org
2026-03-15 14:37:05 -04:00

70 lines
2.9 KiB
Org Mode

** User:
#+begin_src emacs-lisp
(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)
)
)
)
#+end_src
** 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:
1. It first retrieves the ~CREATED~ property of the current headline using ~org-entry-get~.
2. If the property exists, it parses the timestamp using ~org-parse-time-string~ and extracts the
year, month, and day components from the parsed timestamp.
3. It then constructs a target date string in the format ~YYYY-MM-DD~ using the extracted year,
month, and day components.
4. It uses the ~org-roam-dailies-goto~ function (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.
5. 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-notes~ is 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-goto~ function 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.