Skip to content

Commit 6edcef1

Browse files
committed
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 <https://github.com/Stewmath>
1 parent 3e7f48a commit 6edcef1

File tree

4 files changed

+57
-45
lines changed

4 files changed

+57
-45
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
557557

558558
*Fixes*
559559
+ 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.)
560+
+ 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.)
560561
+ 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]].)
561562

562563
** 0.8.8

org-ql.el

+4-2
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,8 @@ COMPARATOR may be `<', `<=', `>', or `>='."
15341534
;; is "h:" while the user is typing.
15351535
(list :regexp (rx bol (1+ "*") " ")
15361536
:case-fold t))
1537-
(`(,predicate-names ,comparator-or-num ,num)
1537+
((and `(,predicate-names ,comparator-or-num ,num)
1538+
(guard (numberp num)))
15381539
(let ((repeat (pcase comparator-or-num
15391540
('< `(repeat 1 ,(1- num) "*"))
15401541
('<= `(repeat 1 ,num "*"))
@@ -1543,7 +1544,8 @@ COMPARATOR may be `<', `<=', `>', or `>='."
15431544
((pred integerp) `(repeat ,comparator-or-num ,num "*")))))
15441545
(list :regexp (rx-to-string `(seq bol ,repeat " ") t)
15451546
:case-fold t)))
1546-
(`(,predicate-names ,num)
1547+
((and `(,predicate-names ,num)
1548+
(guard (numberp num)))
15471549
(list :regexp (rx-to-string `(seq bol (repeat ,num "*") " ") t)
15481550
:case-fold t)))
15491551
;; NOTE: It might be necessary to take into account `org-odd-levels'; see docstring for

org-ql.info

+47-43
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,10 @@ File: README.info, Node: 089-pre, Next: 088, Up: Changelog
10891089
"PROPERTY-NAME" :inherit t)’. (#460
10901090
(https://github.com/alphapapa/org-ql/issues/460). Thanks to
10911091
Stewmath (https://github.com/Stewmath) for reporting.)
1092+
• Predicate ‘level’’s preamble optimizer allows expressions in place
1093+
of the numeric argument (see #460
1094+
(https://github.com/alphapapa/org-ql/issues/460). Thanks to
1095+
Stewmath (https://github.com/Stewmath) for reporting.)
10921096
• Reading of view settings from Org links in upcoming Emacs version.
10931097
(#461 (https://github.com/alphapapa/org-ql/issues/461). Thanks to
10941098
Ola Nilsson (https://github.com/snogge) for help debugging, and for
@@ -2073,49 +2077,49 @@ Node: Links38939
20732077
Node: Tips39626
20742078
Node: Changelog39950
20752079
Node: 089-pre40900
2076-
Node: 08841554
2077-
Node: 08742634
2078-
Node: 08643862
2079-
Node: 08544096
2080-
Node: 08444752
2081-
Node: 08345204
2082-
Node: 08245545
2083-
Node: 08145938
2084-
Node: 0846359
2085-
Node: 07449085
2086-
Node: 07349310
2087-
Node: 07250044
2088-
Node: 07150965
2089-
Node: 0751776
2090-
Node: 06354642
2091-
Node: 06255175
2092-
Node: 06155482
2093-
Node: 0656052
2094-
Node: 05259108
2095-
Node: 05159410
2096-
Node: 0559835
2097-
Node: 04961366
2098-
Node: 04861648
2099-
Node: 04761997
2100-
Node: 04662406
2101-
Node: 04562814
2102-
Node: 04463175
2103-
Node: 04363534
2104-
Node: 04263737
2105-
Node: 04163898
2106-
Node: 0464145
2107-
Node: 03268246
2108-
Node: 03168649
2109-
Node: 0368846
2110-
Node: 02372146
2111-
Node: 02272380
2112-
Node: 02172660
2113-
Node: 0272865
2114-
Node: 0176943
2115-
Node: Notes77044
2116-
Node: Comparison with Org Agenda searches77206
2117-
Node: org-sidebar78095
2118-
Node: License78374
2080+
Node: 08841799
2081+
Node: 08742879
2082+
Node: 08644107
2083+
Node: 08544341
2084+
Node: 08444997
2085+
Node: 08345449
2086+
Node: 08245790
2087+
Node: 08146183
2088+
Node: 0846604
2089+
Node: 07449330
2090+
Node: 07349555
2091+
Node: 07250289
2092+
Node: 07151210
2093+
Node: 0752021
2094+
Node: 06354887
2095+
Node: 06255420
2096+
Node: 06155727
2097+
Node: 0656297
2098+
Node: 05259353
2099+
Node: 05159655
2100+
Node: 0560080
2101+
Node: 04961611
2102+
Node: 04861893
2103+
Node: 04762242
2104+
Node: 04662651
2105+
Node: 04563059
2106+
Node: 04463420
2107+
Node: 04363779
2108+
Node: 04263982
2109+
Node: 04164143
2110+
Node: 0464390
2111+
Node: 03268491
2112+
Node: 03168894
2113+
Node: 0369091
2114+
Node: 02372391
2115+
Node: 02272625
2116+
Node: 02172905
2117+
Node: 0273110
2118+
Node: 0177188
2119+
Node: Notes77289
2120+
Node: Comparison with Org Agenda searches77451
2121+
Node: org-sidebar78340
2122+
Node: License78619
21192123

21202124
End Tag Table
21212125

tests/test-org-ql.el

+5
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,11 @@ with keyword arg NOW in PLIST."
636636
:to-equal (list :query t
637637
:preamble (rx bol (repeat 2 4 "*") " ")
638638
:preamble-case-fold t)))
639+
(it "with an expression in level number's place"
640+
(expect (org-ql--query-preamble '(level <= (string-to-number (property "PROPERTY"))))
641+
:to-equal (list :query '(level <= (string-to-number (property "PROPERTY")))
642+
:preamble nil
643+
:preamble-case-fold t)))
639644
(it "<"
640645
(expect (org-ql--query-preamble '(level < 3))
641646
:to-equal (list :query t

0 commit comments

Comments
 (0)