From 7829238988023c7260072d68d07f3bcf6341d242 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Thu, 8 Aug 2019 10:36:57 -0500 Subject: [PATCH] Add: (org-ql-agenda--agenda) Optionally specify entries directly Should probably refactor this a bit more, but this is useful now. --- README.org | 1 + org-ql-agenda.el | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.org b/README.org index 946ed9c..83a2fa7 100644 --- a/README.org +++ b/README.org @@ -348,6 +348,7 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience + Selector ~(regexp)~ accepts multiple regexps to test. + Macro ~org-ql~ and functions ~org-ql-query~ and ~org-ql-select~ now also accept a comparator function in their ~:sort~ argument. + Function ~org-ql-block~, which works as an Org Agenda series/composite/block command, usable in custom agenda commands defined in variable ~org-agenda-custom-commands~. (Inspired by [[https://github.com/pestctrl/emacs-config/blob/84c557982a860e86d6f67976a82ea776a7bd2c7a/config-org-new.org#my-own-agenda-renderer][Benson Chu's config]].) ++ Function ~org-ql-agenda--agenda~ optionally takes a list of entries as an argument. *Changed* + Function ~org-ql-query~ renamed to ~org-ql-select~. ~org-ql-query~ now refers to a new function. diff --git a/org-ql-agenda.el b/org-ql-agenda.el index 227ea7d..73e734b 100644 --- a/org-ql-agenda.el +++ b/org-ql-agenda.el @@ -201,23 +201,25 @@ SORT: One or a list of `org-ql' sorting functions, like `date' or ;; TODO: Move the action-fn down into --filter-buffer, so users can avoid calling the ;; headline-parser when they don't need it. -(cl-defun org-ql-agenda--agenda (buffers-files query &key sort buffer narrow super-groups) +(cl-defun org-ql-agenda--agenda (buffers-files query &key entries sort buffer narrow super-groups) "FIXME: Docstring" (declare (indent defun)) (when (and super-groups (not org-super-agenda-mode)) (user-error "`org-super-agenda-mode' must be activated to use grouping")) (let* ((org-super-agenda-groups super-groups) - (entries (--> (org-ql-select buffers-files - query - :sort sort - :narrow narrow - :action (lambda () - (->> (org-element-headline-parser (line-end-position)) - org-ql--add-markers))) - (mapcar #'org-ql-agenda--format-element it) - (cond ((bound-and-true-p org-super-agenda-mode) (org-super-agenda--group-items it)) - (t it)) - (s-join "\n" it))) + (entries (or entries + (--> (org-ql-select buffers-files + query + :sort sort + :narrow narrow + :action (lambda () + (->> (org-element-headline-parser (line-end-position)) + org-ql--add-markers)))))) + (string (--> entries + (mapcar #'org-ql-agenda--format-element it) + (cond ((bound-and-true-p org-super-agenda-mode) (org-super-agenda--group-items it)) + (t it)) + (s-join "\n" it))) (buffer (cl-etypecase buffer (string (org-ql-agenda--buffer buffer)) (null (org-ql-agenda--buffer buffer)) @@ -236,7 +238,7 @@ SORT: One or a list of `org-ql' sorting functions, like `date' or (setq-local header-line-format (org-ql-agenda--header-line-format buffers-files query)) ;; Clear buffer, insert entries, etc. (erase-buffer) - (insert entries) + (insert string) (pop-to-buffer (current-buffer)) (org-agenda-finalize) (goto-char (point-min)))))