29 lines
2.3 KiB
EmacsLisp
29 lines
2.3 KiB
EmacsLisp
#s(ellama-session "Emacs function for moving org headers to org-roam-dailies (Open AI)" #s(llm-openai "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" "gpt-4" "text-embedding-3-large") "/home/amr/org/ellama-sessions/Emacs function for moving org headers to org-roam-dailies (Open AI).org" #s(llm-chat-prompt nil nil (#s(llm-chat-prompt-interaction system "" nil) #s(llm-chat-prompt-interaction user "Write an emacs function that moves an org header at point with the property :CREATED: in the format [2009-07-27 Mon 17:12] to an org-roam-dalies node with the same date using org-roam-dailies-find-date
|
|
" nil) #s(llm-chat-prompt-interaction assistant "Below demostrates an Emacs function that does exactly that:
|
|
|
|
```emacs-lisp
|
|
(defun my-org-move-header-to-roam-dailies()
|
|
(interactive)
|
|
(let* ((header-point (point))
|
|
(planning-line (org-get-planning-or-clock-line))
|
|
(created-date-property (when planning-line
|
|
(org-entry-get (point) \"CREATED\")))
|
|
(created-date-timestamp (when created-date-property
|
|
(org-read-date nil nil created-date-property)))
|
|
(created-date (when created-date-timestamp
|
|
(org-time-string-to-time created-date-timestamp)))
|
|
(headers (org-heading-components)))
|
|
(when created-date
|
|
(save-excursion
|
|
(org-cut-subtree)
|
|
(org-roam-dailies-find-date created-date)
|
|
(goto-char (point-max))
|
|
(org-paste-subtree)
|
|
(goto-char header-point)))))
|
|
|
|
```
|
|
Note, org-entry-get is used to retrieve the property :CREATED: from the org header at point. The org-time-string-to-time is used to convert the timestamp string to a time value operational in emacs. This time value is then passed to org-roam-dailies-find-date to open the daily note with the associated date.
|
|
|
|
This function is also wrapped in a save-excursion, which saves the current position of point, so that any movement within the function will return to the original location after the function ends. org-cut-subtree is used to cut the current subtree (the header and all of its sub-headers), and org-paste-subtree is used to paste it into the daily note.
|
|
|
|
Don't forget to add error checking to this function to handle headers that may not have a :CREATED: property, or any other edge cases that may exist in your org files." nil)) nil nil nil) nil) |