From ab3d1178b9ccf1bca4e157c6d88e97299a19648a Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 18 Aug 2019 21:28:06 -0500 Subject: [PATCH] Add: Call some ts-type predicates with a number/auto --- README.org | 26 ++++++++++------ examples.org | 33 +++++++++----------- examples/org-bills-due.el | 2 +- org-ql.el | 64 +++++++++++++++++++++++++++++++++++++++ tests/test-org-ql.el | 41 +++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 30 deletions(-) diff --git a/README.org b/README.org index dcb0b4a..9431fd7 100644 --- a/README.org +++ b/README.org @@ -44,16 +44,16 @@ More examples are available in [[examples.org]]. :action '(org-toggle-tag "Emacs" 'on)) ;; Return a list of bills coming due, searching all Org Agenda files, - ;; sorted by deadline. Deadlines are compared with - ;; `org-deadline-warning-days', which is implied by the plain `<=' in - ;; the `deadline' predicate. `org-ql-query' works like `org-ql-select' - ;; but offers arguments named like SQL queries. + ;; sorted by deadline. The `auto' argument to `deadline' means to match + ;; entries whose deadlines fall within `org-deadline-warning-days'. + ;; `org-ql-query' works like `org-ql-select' but offers arguments named + ;; like SQL queries. (org-ql-query :select #'org-get-heading :from (org-agenda-files) :where '(and (not (done)) (tags "bills") - (deadline <=)) + (deadline auto)) :order-by 'deadline) ;;=> ("TODO Electric bill" "TODO Water bill") @@ -205,17 +205,23 @@ Arguments are listed next to predicate names, where applicable. All of these selectors take optional keyword arguments ~:from~, ~:to:~, and ~:on~. If ~:from~, return non-nil if entry has a timestamp on or after ~:from~. If ~:to~, return non-nil if entry has a timestamp on or before ~:to~. If ~:on~, return non-nil if entry has a timestamp on date ~:on~. Argument values should be either ~ts~ structs, or strings parseable by ~parse-time-string~ which may omit the time value. -+ ~clocked~ :: Return non-nil if current entry was clocked in given period. If no arguments are specified, return non-nil if entry was clocked at any time. Note: Clock entries are expected to be clocked out. Currently clocked entries (i.e. with unclosed timestamp ranges) are ignored. -+ ~closed~ :: Return non-nil if current entry was closed in given period. If no arguments are specified, return non-nil if entry was closed at any time. -+ ~deadline~ :: Return non-nil if current entry has deadline in given period. If no arguments are specified, return non-nil if entry has any deadline. -+ ~planning~ :: Return non-nil if current entry has planning timestamp in given period (i.e. its deadline, scheduled, or closed timestamp). If no arguments are specified, return non-nil if entry is scheduled at any time. -+ ~scheduled~ :: Return non-nil if current entry is scheduled in given period. If no arguments are specified, return non-nil if entry is scheduled at any time. + ~ts~ :: Return non-nil if current entry has a timestamp in given period. If no arguments are specified, return non-nil if entry has any timestamp. + ~ts-active~ :: Like ~ts~, but only matches active timestamps. + ~ts-a~ :: Like ~ts~, but only matches active timestamps. + ~ts-inactive~ :: Like ~ts~, but only matches inactive timestamps. + ~ts-i~ :: Like ~ts~, but only matches inactive timestamps. +The following selectors can also take a single argument, a number, which looks backward or forward a number of days. The number can also be negative to invert the direction. + +*Backward-looking:* ++ ~clocked~ :: Return non-nil if current entry was clocked in given period. If no arguments are specified, return non-nil if entry was clocked at any time. Note: Clock entries are expected to be clocked out. Currently clocked entries (i.e. with unclosed timestamp ranges) are ignored. ++ ~closed~ :: Return non-nil if current entry was closed in given period. If no arguments are specified, return non-nil if entry was closed at any time. + +*Forward-looking:* ++ ~deadline~ :: Return non-nil if current entry has deadline in given period. If argument is =auto=, return non-nil if entry has deadline within =org-deadline-warning-days=. If no arguments are specified, return non-nil if entry has any deadline. ++ ~planning~ :: Return non-nil if current entry has planning timestamp in given period (i.e. its deadline, scheduled, or closed timestamp). If no arguments are specified, return non-nil if entry is scheduled at any time. ++ ~scheduled~ :: Return non-nil if current entry is scheduled in given period. If no arguments are specified, return non-nil if entry is scheduled at any time. + ** Functions / Macros :PROPERTIES: :TOC: ignore-children diff --git a/examples.org b/examples.org index 759ea3e..b90c9da 100644 --- a/examples.org +++ b/examples.org @@ -11,7 +11,7 @@ * Show entries with recent timestamps #+BEGIN_SRC elisp - (cl-defun org-ql-agenda-recent-items (days &optional (type 'ts)) + (cl-defun org-ql-view-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'." @@ -19,28 +19,23 @@ (->> '(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))))) + (org-ql-search (org-agenda-files) + `(,type ,days) + :title "Recent items" + :sort '(date priority todo) + :groups '((:todo "DONE") + (:name "Log" :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) + (org-ql-view-recent-items 7) - ;; Show entries clocked in last 7 days: - (org-ql-agenda-recent-items 30 'clocked) + ;; Show entries clocked in last 30 days: + (org-ql-view-recent-items 30 'clocked) - ;; Show entries closed in last 7 days: - (org-ql-agenda-recent-items 30 'closed) + ;; Show entries closed in last 30 days: + (org-ql-view-recent-items 30 'closed) #+END_SRC * Stuck projects block agenda diff --git a/examples/org-bills-due.el b/examples/org-bills-due.el index 5c7261c..c544734 100644 --- a/examples/org-bills-due.el +++ b/examples/org-bills-due.el @@ -35,7 +35,7 @@ (-if-let* ((header "Bills due within 3 days") (items (org-ql "~/org/main.org" - (and (deadline <= (+ 3 today)) + (and (deadline 3) (tags "bills")) :action (org-get-heading 'no-tags 'no-todo))) (string (concat "