reddit / emacs

Denote journal creation - Copy TODO between files

tassleoff · 2022-11-28 18:14
Hello! I want to automate the creation of a new **denote** journal file each day. I want to verify if it already exists, if not create it and then find the previous journal, check if there are TODO/SCHEDULED/DEADLINE tasks and move them into the new journal. For now I have the following: (require 'cl-lib) ;; needed for cl-return (defun journal-day-exists-p ( target ) "check if journal for a day already exists" (file-expand-wildcards (concat (denote-directory) target "*_journal*.org"))) (defun find-previous-journal () "Find most recent journal" (let* ((today (format-time-string "%Y%m%d")) (all_journals (sort (directory-files "~/Dropbox/orgfiles/denotes" nil "^[0-9].*_journal.*org$") #'string>))) (dolist (journal all_journals) (when (string< (substring journal 0 8) today) (cl-return journal))))) (defun my-denote-journal () "Create an entry tagged 'journal' with the date as its title." (interactive) (let* ((today (format-time-string "%Y%m%d")) (filename (car (journal-day-exists-p today))) (prev (find-previous-journal))) (if filename (find-file filename) (progn (denote (format-time-string "%A %e %B %Y") ; format like Tuesday 14 June 2022 '("journal") nil "~/Denotes") (insert "* Thoughts\n\n* Ideas\n\n* Code\n\n* TASKS\n\n"))))) Now the part where I need help is in moving the Tasks, I already have the idea that I should use org-refile or org-archive, but I am not seeing how to open the previous file and get what I need from it. Can anyone help? &#x200B; Thank you!
takeonrules · 2022-11-28 23:12
I created some similar functionality and thought about using `org-refile` but encountered headwinds. https://github.com/jeremyf/dotemacs/blob/536b03c0c4959ebbcd4152e431f7014ea7fb6146/emacs.d/jf-org-mode.el#L666-L711
tassleoff · 2022-11-29 16:57
u/takeonrules thanks for your reply, I had a look into you configuration but found it a bit too much for my understanding of what is going on. After some work and [inspiration](https://stackoverflow.com/questions/22231431/sort-a-mixed-list-of-headings-in-org-mode/22232709#22232709) (look for function lawlist-refile-tasks) I managed to do what I needed, [here it is!](https://github.com/rjgtorres/emacs_configuration/blob/master/configs/generic_config.org#denote-1) I welcome any advice to make this better. Thanks