From c2b8776ecafcfd2c692754b333f1194d58c633fe Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 18 Aug 2019 23:37:04 -0500 Subject: [PATCH] Change: (org-ql-view-recent-items) Disallow some selectors --- org-ql-agenda.el | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/org-ql-agenda.el b/org-ql-agenda.el index 3c477ff..4406f64 100644 --- a/org-ql-agenda.el +++ b/org-ql-agenda.el @@ -267,20 +267,28 @@ TITLE: An optional string displayed in the header." (cl-defun org-ql-view-recent-items (days &optional (type 'ts) (files (org-agenda-files))) "Show items in FILES from last DAYS days with timestamps of TYPE. -TYPE may be `ts', `ts-active', `ts-inactive', `clocked', -`closed', `deadline', `planning', or `scheduled'." +TYPE may be `ts', `ts-active', `ts-inactive', `clocked', or +`closed'." (interactive (list (read-number "Days: ") - (->> '(ts ts-active ts-inactive clocked closed deadline planning scheduled) + (->> '(ts ts-active ts-inactive clocked closed) (completing-read "Timestamp type: ") intern))) - (org-ql-search 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)))) + ;; It doesn't make much sense to use other date-based selectors to + ;; look into the past, so to prevent confusion, we won't allow them. + (-let* ((query (pcase-exhaustive type + ((or 'ts 'ts-active 'ts-inactive) + ;; These predicates look forward by default, so we must invert the number. + `(,type :from ,(* -1 days) :to 0)) + ((or 'clocked 'closed) + `(,type :from ,days :to 0))))) + (org-ql-search files + query + :title "Recent items" + :sort '(date priority todo) + :groups '((:todo "DONE") + (:name "Log" :category "log" :tag "log") + (:auto-parent t) + (:auto-todo t))))) ;;;; Functions