reddit / emacs

Get a list of TODO in a org agenda file in a string

RadonedWasEaten · 2022-07-23 15:07
I was looking for a function or something that could just return a list of all TODO items in my org agenda ordered by the time they are due. Like if I have X due tomorrow and y due the day after tomorrow I could get something like: ‘X y’ By a call of a single function
dm_g · 2022-07-23 21:19
I have done something similar. The following code might inspire you. It scans the org-agenda files looking for NEXT actions,applies to the item the function dmg-build-link and returns it. What I suggest you do is: create an action that returns a list of the file, headline, schedule time. Then you can order them accordingly. (defun dmg-insert-next-agenda-actions () (interactive) (insert (apply 'concat (mapcar (lambda (entry) (concat "- " entry "\n") ) (org-ql-select (org-agenda-files) '(todo "NEXT") :action 'dmg-build-link )))))
AuroraDraco · 2022-07-24 22:45
`org-heading-components` returns various pieces of information about an org heading. You could run a loop over every heading in a document where you collect the heading name of every heading whose TODO component is not nil (shouldn't be too hard if you are familiar with the `cl-loop` or `dotimes` macros. I don't use the org-agenda extensively, so I am not sure if there is a simpler way to do it. It would surprise me if something such as org-ql can't write a query that returns this exact thing. Org-ql is quite potent, so you could definitely look more into that as well for the solution if you don't want to write your own from scratch. Would try to help more with the code but I don't have my pc on me rn to do so.