From 3f4bd05a9f3794a5af16cfb69da1a24dc481dc6b Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 20 Mar 2022 19:14:33 -0500 Subject: [PATCH 1/3] WIP: Temporarily disable sorter validation --- org-ql.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org-ql.el b/org-ql.el index ffed560..9f42d06 100644 --- a/org-ql.el +++ b/org-ql.el @@ -417,7 +417,10 @@ each priority the newest items would appear first." (org-ql--sort-by items (-list sort))) ;; Sort by user-given comparator. ((pred functionp) (-sort sort items)) - (_ (user-error "SORT must be either nil, one or a list of the defined sorting methods (see documentation), or a comparison function of two arguments"))))) + ;; FIXME: Test more carefully for sorters with arguments. In the meantime, just try to sort. + (_ (org-ql--sort-by items (-list sort))) + ;; (_ (user-error "SORT must be either nil, one or a list of the defined sorting methods (see documentation), or a comparison function of two arguments")) + ))) ;;;###autoload (cl-defun org-ql-query (&key (select 'element-with-markers) from where narrow order-by) From 9394152f4313d3fdc28c97026168957d7ba6c52b Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 20 Mar 2022 19:14:45 -0500 Subject: [PATCH 2/3] WIP: Add tags sorter --- org-ql.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/org-ql.el b/org-ql.el index 9f42d06..deefcf6 100644 --- a/org-ql.el +++ b/org-ql.el @@ -2166,6 +2166,13 @@ PREDICATES is a list of one or more sorting methods, including: (= 0 (random 2)))) ;; NOTE: reverse and todo are handled below. ;; TODO: Add more. + (`(tags . ,tags) (lambda (a b) + "Return non-nil if A has certain tags and B doesn't." + (cl-flet ((test-entry + (entry) (org-with-point-at (org-element-property :org-hd-marker entry) + (apply #'org-ql--predicate-tags tags)))) + (and (test-entry a) + (not (test-entry b)))))) (_ (user-error "Invalid sorting predicate: %s" symbol)))) (sort-by-todo-keyword (items) (let* ((grouped-items (--group-by (when-let (keyword (org-element-property :todo-keyword it)) From e8eff5d798bcdb3124b1e1f147dc871b0c313cd6 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Sun, 20 Mar 2022 19:33:23 -0500 Subject: [PATCH 3/3] WIP: Add category sorter --- org-ql.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/org-ql.el b/org-ql.el index deefcf6..f63a363 100644 --- a/org-ql.el +++ b/org-ql.el @@ -2160,7 +2160,8 @@ PREDICATES is a list of one or more sorting methods, including: ((or 'deadline 'scheduled 'closed) (apply-partially #'org-ql--date-type< (intern (concat ":" (symbol-name symbol))))) ;; TODO: Rename `date' to `planning'. `date' should be something else. - ('date #'org-ql--date<) + ('category #'org-ql--category<) + ('date #'org-ql--date<) ('priority #'org-ql--priority<) ('random (lambda (&rest _ignore) (= 0 (random 2)))) @@ -2195,6 +2196,17 @@ PREDICATES is a list of one or more sorting methods, including: (_ (-sort (sorter pred) items))))) items)) +(defun org-ql--category< (a b) + "Return non-nil if A's category is alphabetically less than B's." + (cl-macrolet ((category (element) + `(org-with-point-at (org-element-property :org-hd-marker ,element) + (org-get-category (point))))) + (let ((a-category (category a)) + (b-category (category b))) + (if (and a-category b-category) + (string< a-category b-category) + a-category)))) + ;; TODO: Rewrite date sorters using `ts'. (defun org-ql--date-type< (type a b)