diff --git a/README.org b/README.org index 9431fd7..0e38d79 100644 --- a/README.org +++ b/README.org @@ -170,6 +170,10 @@ Here's an example of using it to generate an agenda-like view for certain files Choose and display a view stored in ~org-ql-views~. +*** org-ql-view-recent-items + +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~. =FILES= defaults to those returned by the function =org-agenda-files=. + ** Queries A query is a lisp form which may contain arbitrary lisp forms, as well as certain built-in predicates. It is byte-compiled into a predicate function which is tested with point on each heading in an Org buffer; when it returns non-nil, the heading matches the query. diff --git a/examples.org b/examples.org index b90c9da..2750e9c 100644 --- a/examples.org +++ b/examples.org @@ -10,24 +10,9 @@ * Show entries with recent timestamps -#+BEGIN_SRC elisp - (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'." - (interactive (list (read-number "Days: ") - (->> '(ts ts-active ts-inactive clocked closed deadline planning scheduled) - (completing-read "Timestamp type: ") - intern))) - (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)))) +You can also access these views with the command ~org-ql-view~. +#+BEGIN_SRC elisp ;; Show entries with any timestamp from last 7 days: (org-ql-view-recent-items 7) diff --git a/org-ql-agenda.el b/org-ql-agenda.el index b62eeb2..3c477ff 100644 --- a/org-ql-agenda.el +++ b/org-ql-agenda.el @@ -80,24 +80,7 @@ Based on `org-agenda-mode-map'.") ;;;; Customization (defcustom org-ql-views - (list (cons "Recent entries" (cl-function - (lambda (days &optional (type 'ts)) - (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 Entries" - :sort '(date priority todo) - :groups '((:todo "DONE") - (:auto-parent t) - (:auto-todo t))))))) + (list (cons "Recent entries" #'org-ql-view-recent-items) (cons "Stuck Projects" (lambda () (interactive) (org-ql-search (org-agenda-files) @@ -282,6 +265,23 @@ TITLE: An optional string displayed in the header." (interactive (list (completing-read "View: " (mapcar #'car org-ql-views)))) (call-interactively (alist-get view org-ql-views nil nil #'string=))) +(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'." + (interactive (list (read-number "Days: ") + (->> '(ts ts-active ts-inactive clocked closed deadline planning scheduled) + (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)))) + ;;;; Functions ;; TODO: Move the action-fn down into --filter-buffer, so users can avoid calling the