From 5ea97d22721475a920ca57532eb482b2bf545246 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Thu, 5 Sep 2024 15:49:11 -0500 Subject: [PATCH] Fix: (level) Check number argument for preamble This allows a query like this: (level <= (string-to-number (property PROPERTY))) to proceed without signaling an error from ORG-QL--QUERY-PREAMBLE. See #460. Reported-by: Stewmath --- README.org | 1 + org-ql.el | 6 ++- org-ql.info | 90 +++++++++++++++++++++++--------------------- tests/test-org-ql.el | 5 +++ 4 files changed, 57 insertions(+), 45 deletions(-) diff --git a/README.org b/README.org index bb6c589..36d8031 100644 --- a/README.org +++ b/README.org @@ -557,6 +557,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like: *Fixes* + Predicate ~property~ when called with argument form ~(property "PROPERTY-NAME" :inherit t)~. ([[https://github.com/alphapapa/org-ql/issues/460][#460]]. Thanks to [[https://github.com/Stewmath][Stewmath]] for reporting.) ++ Predicate ~level~'s preamble optimizer allows expressions in place of the numeric argument. (See [[https://github.com/alphapapa/org-ql/issues/460][#460]]. Thanks to [[https://github.com/Stewmath][Stewmath]] for reporting.) + Reading of view settings from Org links in upcoming Emacs version. ([[https://github.com/alphapapa/org-ql/issues/461][#461]]. Thanks to [[https://github.com/snogge][Ola Nilsson]] for help debugging, and for maintaining [[https://github.com/jorgenschaefer/emacs-buttercup][Buttercup]].) ** 0.8.8 diff --git a/org-ql.el b/org-ql.el index 9ff8d71..40266e3 100644 --- a/org-ql.el +++ b/org-ql.el @@ -1534,7 +1534,8 @@ COMPARATOR may be `<', `<=', `>', or `>='." ;; is "h:" while the user is typing. (list :regexp (rx bol (1+ "*") " ") :case-fold t)) - (`(,predicate-names ,comparator-or-num ,num) + ((and `(,predicate-names ,comparator-or-num ,num) + (guard (numberp num))) (let ((repeat (pcase comparator-or-num ('< `(repeat 1 ,(1- num) "*")) ('<= `(repeat 1 ,num "*")) @@ -1543,7 +1544,8 @@ COMPARATOR may be `<', `<=', `>', or `>='." ((pred integerp) `(repeat ,comparator-or-num ,num "*"))))) (list :regexp (rx-to-string `(seq bol ,repeat " ") t) :case-fold t))) - (`(,predicate-names ,num) + ((and `(,predicate-names ,num) + (guard (numberp num))) (list :regexp (rx-to-string `(seq bol (repeat ,num "*") " ") t) :case-fold t))) ;; NOTE: It might be necessary to take into account `org-odd-levels'; see docstring for diff --git a/org-ql.info b/org-ql.info index c11c851..e2ab21f 100644 --- a/org-ql.info +++ b/org-ql.info @@ -1089,6 +1089,10 @@ File: README.info, Node: 089-pre, Next: 088, Up: Changelog "PROPERTY-NAME" :inherit t)’. (#460 (https://github.com/alphapapa/org-ql/issues/460). Thanks to Stewmath (https://github.com/Stewmath) for reporting.) + • Predicate ‘level’’s preamble optimizer allows expressions in place + of the numeric argument. (See #460 + (https://github.com/alphapapa/org-ql/issues/460). Thanks to + Stewmath (https://github.com/Stewmath) for reporting.) • Reading of view settings from Org links in upcoming Emacs version. (#461 (https://github.com/alphapapa/org-ql/issues/461). Thanks to Ola Nilsson (https://github.com/snogge) for help debugging, and for @@ -2073,49 +2077,49 @@ Node: Links38939 Node: Tips39626 Node: Changelog39950 Node: 089-pre40900 -Node: 08841554 -Node: 08742634 -Node: 08643862 -Node: 08544096 -Node: 08444752 -Node: 08345204 -Node: 08245545 -Node: 08145938 -Node: 0846359 -Node: 07449085 -Node: 07349310 -Node: 07250044 -Node: 07150965 -Node: 0751776 -Node: 06354642 -Node: 06255175 -Node: 06155482 -Node: 0656052 -Node: 05259108 -Node: 05159410 -Node: 0559835 -Node: 04961366 -Node: 04861648 -Node: 04761997 -Node: 04662406 -Node: 04562814 -Node: 04463175 -Node: 04363534 -Node: 04263737 -Node: 04163898 -Node: 0464145 -Node: 03268246 -Node: 03168649 -Node: 0368846 -Node: 02372146 -Node: 02272380 -Node: 02172660 -Node: 0272865 -Node: 0176943 -Node: Notes77044 -Node: Comparison with Org Agenda searches77206 -Node: org-sidebar78095 -Node: License78374 +Node: 08841801 +Node: 08742881 +Node: 08644109 +Node: 08544343 +Node: 08444999 +Node: 08345451 +Node: 08245792 +Node: 08146185 +Node: 0846606 +Node: 07449332 +Node: 07349557 +Node: 07250291 +Node: 07151212 +Node: 0752023 +Node: 06354889 +Node: 06255422 +Node: 06155729 +Node: 0656299 +Node: 05259355 +Node: 05159657 +Node: 0560082 +Node: 04961613 +Node: 04861895 +Node: 04762244 +Node: 04662653 +Node: 04563061 +Node: 04463422 +Node: 04363781 +Node: 04263984 +Node: 04164145 +Node: 0464392 +Node: 03268493 +Node: 03168896 +Node: 0369093 +Node: 02372393 +Node: 02272627 +Node: 02172907 +Node: 0273112 +Node: 0177190 +Node: Notes77291 +Node: Comparison with Org Agenda searches77453 +Node: org-sidebar78342 +Node: License78621  End Tag Table diff --git a/tests/test-org-ql.el b/tests/test-org-ql.el index baf79c4..fab9ea9 100644 --- a/tests/test-org-ql.el +++ b/tests/test-org-ql.el @@ -636,6 +636,11 @@ with keyword arg NOW in PLIST." :to-equal (list :query t :preamble (rx bol (repeat 2 4 "*") " ") :preamble-case-fold t))) + (it "with an expression in level number's place" + (expect (org-ql--query-preamble '(level <= (string-to-number (property "PROPERTY")))) + :to-equal (list :query '(level <= (string-to-number (property "PROPERTY"))) + :preamble nil + :preamble-case-fold t))) (it "<" (expect (org-ql--query-preamble '(level < 3)) :to-equal (list :query t