@@ -1735,29 +1735,28 @@ priority B)."
1735
1735
`(priority ', comparator , letter )))
1736
1736
1737
1737
: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 )
1741
1739
; ; 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 )))
1743
1741
(`(, predicate-names ,(and (or ''= ''< ''> ''<= ''>= ) comparator) , letter )
1744
1742
; ; Comparator and priority letter.
1745
1743
; ; 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 ))))
1747
1746
(index (-elem-index letter priority-letters))
1748
1747
; ; NOTE: Higher priority == lower number.
1749
1748
; ; NOTE: Because we need to support both preamble-based queries and
1750
1749
; ; regular predicate ones, we work around an idiosyncrasy of query
1751
1750
; ; pre-processing by accepting both quoted and double-quoted comparator
1752
1751
; ; 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)))))
1759
1758
(list :regexp (rx-to-string `(seq bol (1+ " *" ) (1+ blank) (optional (1+ upper) (1+ blank))
1760
- " [#" (in , priorities ) " ]" ) t ))))
1759
+ " [#" (or ,@ priorities ) " ]" ) t ))))
1761
1760
(`(, predicate-names . , letters )
1762
1761
; ; One or more priorities.
1763
1762
; ; MAYBE: Disable case-folding.
@@ -1780,11 +1779,11 @@ priority B)."
1780
1779
(`(,(and (or '= '< '> '<= '>= ) comparator) , priority-arg )
1781
1780
; ; Comparator and priority arguments given: compare item priority using them.
1782
1781
(funcall comparator item-priority
1783
- (* 1000 ( - org-lowest -priority (string-to-char priority-arg) ))))
1782
+ (org-get -priority (format " [# %s ] " priority-arg))))
1784
1783
(_
1785
1784
; ; List of priorities given as arguments: compare each of them to item priority using =.
1786
1785
(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))))))))
1788
1787
1789
1788
(org-ql-defpred property (property &optional value &key inherit)
1790
1789
" Return non-nil if current entry has PROPERTY, and optionally VALUE.
@@ -2501,11 +2500,20 @@ A and B are Org timestamp elements."
2501
2500
(a-ts t )
2502
2501
(b-ts nil )))))
2503
2502
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
+
2504
2512
(defun org-ql--priority< (a b )
2505
2513
" Return non-nil if A's priority is higher than B's.
2506
2514
A and B are Org headline elements."
2507
2515
(cl-macrolet ((priority (item)
2508
- `(org-element-property : priority , item )))
2516
+ `(org-ql-- priority-to-value , item )))
2509
2517
; ; NOTE: Priorities are numbers in Org elements. This might differ from the priority selector logic.
2510
2518
(let ((a-priority (priority a))
2511
2519
(b-priority (priority b)))
0 commit comments