Add: org-ql-view-recent-items

This commit is contained in:
Adam Porter 2019-08-18 21:40:51 -05:00
parent ab3d1178b9
commit c2ecbc67a5
3 changed files with 24 additions and 35 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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