Skip to content

Commit f97a13a

Browse files
committed
Feat: Enable all valid priority values
Expand recognised priority values from A-C to current org-mode standard of A-Z and 0-64.
1 parent b6f8a31 commit f97a13a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

org-ql.el

+23-15
Original file line numberDiff line numberDiff line change
@@ -1735,29 +1735,28 @@ priority B)."
17351735
`(priority ',comparator ,letter)))
17361736

17371737
:preambles
1738-
(;; NOTE: This only accepts A, B, or C. I haven't seen
1739-
;; other priorities in the wild, so this will do for now.
1740-
(`(,predicate-names)
1738+
((`(,predicate-names)
17411739
;; Any priority cookie.
1742-
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl) "[#" (in "ABC") "]") t)))
1740+
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl) "[#" (or (in "A-Z") (1+ (in "0-9"))) "]") t)))
17431741
(`(,predicate-names ,(and (or ''= ''< ''> ''<= ''>=) comparator) ,letter)
17441742
;; Comparator and priority letter.
17451743
;; NOTE: The double-quoted comparators. See below.
1746-
(let* ((priority-letters '("A" "B" "C"))
1744+
(let* ((priority-letters (append (mapcar #'number-to-string (number-sequence 0 64))
1745+
(mapcar #'string (number-sequence ?A ?Z))))
17471746
(index (-elem-index letter priority-letters))
17481747
;; NOTE: Higher priority == lower number.
17491748
;; NOTE: Because we need to support both preamble-based queries and
17501749
;; regular predicate ones, we work around an idiosyncrasy of query
17511750
;; pre-processing by accepting both quoted and double-quoted comparator
17521751
;; function symbols. Not the most elegant solution, but it works.
1753-
(priorities (s-join "" (pcase comparator
1754-
((or '= ''=) (list letter))
1755-
((or '> ''>) (cl-subseq priority-letters 0 index))
1756-
((or '>= ''>=) (cl-subseq priority-letters 0 (1+ index)))
1757-
((or '< ''<) (cl-subseq priority-letters (1+ index)))
1758-
((or '<= ''<=) (cl-subseq priority-letters index))))))
1752+
(priorities (pcase comparator
1753+
((or '= ''=) (list letter))
1754+
((or '> ''>) (cl-subseq priority-letters 0 index))
1755+
((or '>= ''>=) (cl-subseq priority-letters 0 (1+ index)))
1756+
((or '< ''<) (cl-subseq priority-letters (1+ index)))
1757+
((or '<= ''<=) (cl-subseq priority-letters index)))))
17591758
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (optional (1+ upper) (1+ blank))
1760-
"[#" (in ,priorities) "]") t))))
1759+
"[#" (or ,@priorities) "]") t))))
17611760
(`(,predicate-names . ,letters)
17621761
;; One or more priorities.
17631762
;; MAYBE: Disable case-folding.
@@ -1780,11 +1779,11 @@ priority B)."
17801779
(`(,(and (or '= '< '> '<= '>=) comparator) ,priority-arg)
17811780
;; Comparator and priority arguments given: compare item priority using them.
17821781
(funcall comparator item-priority
1783-
(* 1000 (- org-lowest-priority (string-to-char priority-arg)))))
1782+
(org-get-priority (format "[#%s]" priority-arg))))
17841783
(_
17851784
;; List of priorities given as arguments: compare each of them to item priority using =.
17861785
(cl-loop for priority-arg in args
1787-
thereis (= item-priority (* 1000 (- org-lowest-priority (string-to-char priority-arg)))))))))
1786+
thereis (= item-priority (org-get-priority (format "[#%s]" priority-arg))))))))
17881787

17891788
(org-ql-defpred property (property &optional value &key inherit)
17901789
"Return non-nil if current entry has PROPERTY, and optionally VALUE.
@@ -2501,11 +2500,20 @@ A and B are Org timestamp elements."
25012500
(a-ts t)
25022501
(b-ts nil)))))
25032502

2503+
(defun org-ql--priority-to-value (el)
2504+
"Return an integer suitable for sorting priorities."
2505+
(let ((prio (org-element-property :priority el)))
2506+
(cond
2507+
((not prio) (org-priority-to-value (org-element-property :raw-value el)))
2508+
((not (integerp prio)) nil)
2509+
((<= ?0 prio ?9) (- prio ?0))
2510+
(t prio))))
2511+
25042512
(defun org-ql--priority< (a b)
25052513
"Return non-nil if A's priority is higher than B's.
25062514
A and B are Org headline elements."
25072515
(cl-macrolet ((priority (item)
2508-
`(org-element-property :priority ,item)))
2516+
`(org-ql--priority-to-value ,item)))
25092517
;; NOTE: Priorities are numbers in Org elements. This might differ from the priority selector logic.
25102518
(let ((a-priority (priority a))
25112519
(b-priority (priority b)))

0 commit comments

Comments
 (0)