3.3 KiB
3.3 KiB
org-ql examples
Show entries with recent timestamps
(cl-defun org-ql-agenda-recent-items (days &optional (type 'ts))
"Show items from previous DAYS days with timestamps of TYPE.
TYPE may be `ts', `ts-active', `ts-inactive', `clocked',
`closed', `deadline', `planning', or `scheduled'."
(interactive (list (read-number "Days: ")
(->> '(ts ts-active ts-inactive clocked closed deadline planning scheduled)
(completing-read "Timestamp type: ")
intern)))
(let ((from (->> (ts-now)
(ts-adjust 'day (* -1 days))
(ts-apply :hour 0 :minute 0 :second 0)
;; Formatting isn't required, but it looks better in the header than a struct.
ts-format)))
(org-ql-search (org-agenda-files)
`(,type :from ,from :to ,(ts-format (ts-now)))
:title "Recent items"
:sort '(date priority todo)
:groups '((:todo "DONE")
(:category "log" :tag "log")
(:auto-parent t)
(:auto-todo t)))))
;; Show entries with any timestamp from last 7 days:
(org-ql-agenda-recent-items 7)
;; Show entries clocked in last 7 days:
(org-ql-agenda-recent-items 30 'clocked)
;; Show entries closed in last 7 days:
(org-ql-agenda-recent-items 30 'closed)
Stuck projects block agenda
Reddit user emptymatrix shared this example of replacing a traditional org-stuck-projects view like:
(setq org-stuck-projects
'("+@project/-DONE" ("NEXT") nil "SCHEDULED:"))
With this org-ql-block agenda view, like:
(setq org-agenda-custom-commands
'(("s" "Stuck Projects"
((org-ql-block '(and (tags "@project")
(not (done))
(not (descendants (todo "NEXT")))
(not (descendants (scheduled)))))))))
Listing bills coming due
This uses the example in the readme file, but maps across the elements returned by org-ql to present a simple list of titles and deadlines.
(--map (list (org-element-property :raw-value it)
(org-timestamp-format (org-element-property :deadline it) "%c"))
(org-ql (org-agenda-files)
(and (not (done))
(tags "bills")
(deadline <=))
:sort deadline))
;;=> (("Electric bill" "Thu 23 Aug 2018 12:00:00 AM CDT")
;; ("Rent" "Sat 01 Sep 2018 08:00:00 PM CDT"))
This could also be put in a script, which could use desktop notifications to remind of bills coming due: org-bills-due.el.