Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
Adam Porter
e8eff5d798 WIP: Add category sorter 2022-03-20 19:33:23 -05:00
Adam Porter
9394152f43 WIP: Add tags sorter 2022-03-20 19:14:45 -05:00
Adam Porter
3f4bd05a9f WIP: Temporarily disable sorter validation 2022-03-20 19:14:33 -05:00

View file

@ -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)
@ -2157,12 +2160,20 @@ 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))))
;; 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))
@ -2185,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)