Skip to content

Commit

Permalink
Fix: (level) Check number argument for preamble
Browse files Browse the repository at this point in the history
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 <https://github.com/Stewmath>
  • Loading branch information
alphapapa committed Sep 5, 2024
1 parent 3e7f48a commit 5ea97d2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 45 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions org-ql.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "*"))
Expand All @@ -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
Expand Down
90 changes: 47 additions & 43 deletions org-ql.info
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions tests/test-org-ql.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ea97d2

Please sign in to comment.