116 lines
4.6 KiB
Org Mode
116 lines
4.6 KiB
Org Mode
#+TITLE: org-ql examples
|
|
|
|
* Contents
|
|
:PROPERTIES:
|
|
:TOC: this
|
|
:END:
|
|
- [[#stored-views-command][Stored views command]]
|
|
- [[#show-entries-with-timestamps-in-the-last-n-days][Show entries with timestamps in the last N days]]
|
|
- [[#stuck-projects-block-agenda][Stuck projects block agenda]]
|
|
- [[#listing-bills-coming-due][Listing bills coming due]]
|
|
|
|
* Stored views command
|
|
|
|
This defines a simple list of stored views and a command to easily access them with completion, which may be more convenient than defining a command for each view.
|
|
|
|
#+BEGIN_SRC elisp
|
|
(defun org-ql-view (&optional view)
|
|
"Choose and display a stored `org-ql' view."
|
|
(interactive (list (completing-read "View: " (mapcar #'car org-ql-views))))
|
|
(funcall (alist-get view org-ql-views nil nil #'string=)))
|
|
|
|
(setq org-ql-views
|
|
(list (cons "Stuck Projects" (lambda ()
|
|
(org-ql-agenda (org-agenda-files)
|
|
(and (todo)
|
|
(not (todo "TO-WATCH" "TO-READ" "MAYBE" "SOMEDAY"))
|
|
(children)
|
|
(not (children (todo)))
|
|
(not (habit)))
|
|
:title "Stuck Projects"
|
|
:sort (priority date)
|
|
:super-groups ((:name "Home" :tag "home")
|
|
(:tag ("Emacs" "computer") :order 100)
|
|
(:auto-parent t)
|
|
(:todo "WAITING")
|
|
(:auto-category t)))))))
|
|
#+END_SRC
|
|
|
|
* Show entries with timestamps in the last N days
|
|
|
|
#+BEGIN_SRC elisp
|
|
(cl-defun org-ql-agenda-last-days (days &optional (type 'ts))
|
|
"Show entries 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-now)))))
|
|
|
|
;; Show entries with any timestamp from last 7 days:
|
|
(org-ql-agenda-last-days 7)
|
|
|
|
;; Show entries clocked in last 7 days:
|
|
(org-ql-agenda-last-days 30 'clocked)
|
|
|
|
;; Show entries closed in last 7 days:
|
|
(org-ql-agenda-last-days 30 'closed)
|
|
#+END_SRC
|
|
|
|
* Stuck projects block agenda
|
|
|
|
Reddit user =emptymatrix= [[https://www.reddit.com/r/emacs/comments/cnrt2d/orgqlblock_integrates_orgql_into_org_agenda/ewtqez8/][shared]] this example of replacing a traditional =org-stuck-projects= view like:
|
|
|
|
#+BEGIN_SRC elisp
|
|
(setq org-stuck-projects
|
|
'("+@project/-DONE" ("NEXT") nil "SCHEDULED:"))
|
|
#+END_SRC
|
|
|
|
With this =org-ql-block= agenda view, like:
|
|
|
|
#+BEGIN_SRC elisp
|
|
(setq org-agenda-custom-commands
|
|
'(("s" "Stuck Projects"
|
|
((org-ql-block '(and (tags "@project")
|
|
(not (done))
|
|
(not (descendants (todo "NEXT")))
|
|
(not (descendants (scheduled)))))))))
|
|
#+END_SRC
|
|
|
|
* 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.
|
|
|
|
#+BEGIN_SRC elisp
|
|
(--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"))
|
|
#+END_SRC
|
|
|
|
This could also be put in a script, which could use desktop notifications to remind of bills coming due: [[examples/org-bills-due.el][org-bills-due.el]].
|
|
|
|
* COMMENT Code :noexport:
|
|
:PROPERTIES:
|
|
:TOC: ignore
|
|
:END:
|
|
|
|
** File-local variables
|
|
|
|
# Local Variables:
|
|
# eval: (require 'org-make-toc)
|
|
# before-save-hook: org-make-toc
|
|
# End:
|