43 lines
1.9 KiB
Org Mode
43 lines
1.9 KiB
Org Mode
** 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
|
|
|
|
** Ellama:
|
|
Here is an Emacs Lisp function that might work for this case:
|
|
#+BEGIN_SRC elisp
|
|
(defun my/move-header-to-org-roam-dailies-node ()
|
|
"Move current org header with :CREATED: to org-roam-dailies node specified by :CREATED: date."
|
|
(interactive)
|
|
(when (org-entry-get nil "CREATED")
|
|
(let* ((creation-date (org-entry-get nil "CREATED"))
|
|
(date (org-read-date nil nil creation-date))
|
|
(entry (org-cut-subtree))
|
|
(dest-buffer (org-roam-dailies-find-date (org-time-string-to-time date))))
|
|
(unless (buffer-live-p dest-buffer)
|
|
(error "No destination buffer could be found."))
|
|
(with-current-buffer dest-buffer
|
|
;; Go to the end of buffer, can be customized if needed
|
|
(goto-char (point-max))
|
|
(unless (= (point) (point-min)) (insert "\n"))
|
|
(insert entry)
|
|
;; Save buffer if needed
|
|
(when (buffer-modified-p) (save-buffer))))
|
|
;; Optionally, delete empty lines after cutting the entry
|
|
(setq delete-trailing-lines t)))
|
|
#+END_SRC
|
|
|
|
This function does the following:
|
|
|
|
- It checks if current header has a ~:CREATED:~ property.
|
|
- If it does, then stores the value/date of the ~:CREATED:~ property and cuts (removes) the current
|
|
header (org subtree).
|
|
- Then, it uses ~org-roam-dailies-find-date~ with the ~:CREATED:~ value/date to switch to that
|
|
org-roam-dailies buffer.
|
|
- It then appends the removed header at the end of the buffer (could be customized to put it
|
|
elsewhere).
|
|
- It can also optionally save the buffer and clean up trailing empty lines after cutting the header.
|
|
|
|
Remember to customize this function for your needs, especially to set where in the destination
|
|
buffer should the header be pasted.
|
|
|
|
|