WIP: Add category sorter

This commit is contained in:
Adam Porter 2022-03-20 19:33:23 -05:00
parent 9394152f43
commit e8eff5d798

View file

@ -2160,6 +2160,7 @@ 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.
('category #'org-ql--category<)
('date #'org-ql--date<)
('priority #'org-ql--priority<)
('random (lambda (&rest _ignore)
@ -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)