Skip to content

Commit 86d3387

Browse files
committed
Fix: (property) Calling like (property PROPERTY :inherit t)
Supporting this form isn't really required, since it violates the CL-style argument parsing of CL-DEFUN, but it's convenient, and probably saves some hair-pulling for users who are less familiar with Elisp. Fixes #460. Reported-by: Stewmath <https://github.com/Stewmath>
1 parent a373e81 commit 86d3387

File tree

4 files changed

+98
-57
lines changed

4 files changed

+98
-57
lines changed

README.org

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

558558
*Fixes*
559+
+ 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.)
559560
+ 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]].)
560561

561562
** 0.8.8

org-ql.el

+41-13
Original file line numberDiff line numberDiff line change
@@ -1799,34 +1799,62 @@ interpreted as nil or non-nil)."
17991799
;; predicate test for whether an entry has local
18001800
;; properties when no arguments are given.
18011801
(list 'property ""))
1802-
(`(,predicate-names ,property ,value . ,plist)
1802+
(`(,predicate-names ,property)
18031803
;; Convert keyword property arguments to strings. Non-sexp
18041804
;; queries result in keyword property arguments (because to do
18051805
;; otherwise would require ugly special-casing in the parsing).
18061806
(when (keywordp property)
18071807
(setf property (substring (symbol-name property) 1)))
1808-
(list 'property property value
1809-
:inherit (cond ((plist-member plist :inherit) (plist-get plist :inherit))
1810-
((listp org-use-property-inheritance) ''selective)
1811-
(t org-use-property-inheritance)))))
1808+
(list 'property property))
1809+
(`(,predicate-names ,property . ,rest)
1810+
(pcase rest
1811+
(`(,value)
1812+
;; Convert keyword property arguments to strings. Non-sexp
1813+
;; queries result in keyword property arguments (because to do
1814+
;; otherwise would require ugly special-casing in the parsing).
1815+
(when (keywordp property)
1816+
(setf property (substring (symbol-name property) 1)))
1817+
(list 'property property value))
1818+
((and `(,value . ,plist)
1819+
(guard (not (keywordp value))))
1820+
;; Convert keyword property arguments to strings. Non-sexp
1821+
;; queries result in keyword property arguments (because to do
1822+
;; otherwise would require ugly special-casing in the parsing).
1823+
(when (keywordp property)
1824+
(setf property (substring (symbol-name property) 1)))
1825+
(list 'property property value
1826+
:inherit (cond ((plist-member plist :inherit) (plist-get plist :inherit))
1827+
((listp org-use-property-inheritance) ''selective)
1828+
(t org-use-property-inheritance))))
1829+
((and plist (guard (keywordp (car rest))))
1830+
;; Convert keyword property arguments to strings. Non-sexp
1831+
;; queries result in keyword property arguments (because to do
1832+
;; otherwise would require ugly special-casing in the parsing).
1833+
(when (keywordp property)
1834+
(setf property (substring (symbol-name property) 1)))
1835+
(list 'property property nil
1836+
:inherit (cond ((plist-member plist :inherit) (plist-get plist :inherit))
1837+
((listp org-use-property-inheritance) ''selective)
1838+
(t org-use-property-inheritance)))))))
18121839
;; MAYBE: Should case folding be disabled for properties? What about values?
18131840
;; MAYBE: Support (property) without args.
18141841

18151842
;; NOTE: When inheritance is enabled, the preamble can't be used,
18161843
;; which will make the search slower.
1817-
:preambles ((`(,predicate-names ,property ,value . ,(map :inherit))
1844+
:preambles (((and `(,predicate-names ,property ,value)
1845+
(guard (atom value)))
18181846
;; We do NOT return nil, because the predicate still needs to be tested,
18191847
;; because the regexp could match a string not inside a property drawer.
1820-
(list :regexp (unless inherit
1821-
(rx-to-string `(seq bol (0+ space) ":" ,property ":"
1822-
(1+ space) ,value (0+ space) eol)))
1848+
(list :regexp (rx-to-string `(seq bol (0+ space) ":" ,property ":"
1849+
(1+ space) ,value (0+ space) eol))
18231850
:query query))
1824-
(`(,predicate-names ,property . ,(map :inherit))
1825-
;; We do NOT return nil, because the predicate still needs to be tested,
1851+
((and `(,predicate-names ,property ,value . ,plist)
1852+
(guard (keywordp (car plist))))
1853+
;; WE do NOT return nil, because the predicate still needs to be tested,
18261854
;; because the regexp could match a string not inside a property drawer.
18271855
;; NOTE: The preamble only matches if there appears to be a value.
18281856
;; A line like ":ID: " without any other text does not match.
1829-
(list :regexp (unless inherit
1857+
(list :regexp (unless (plist-get plist :inherit)
18301858
(rx-to-string `(seq bol (0+ space) ":" ,property ":" (1+ space)
18311859
(minimal-match (1+ not-newline)) eol)))
18321860
:query query)))
@@ -1838,7 +1866,7 @@ interpreted as nil or non-nil)."
18381866
;; Check that PROPERTY exists
18391867
(org-ql--value-at
18401868
(point) (lambda ()
1841-
(org-entry-get (point) property))))
1869+
(org-entry-get (point) property inherit))))
18421870
(_
18431871
;; Check that PROPERTY has VALUE.
18441872

org-ql.info

+47-43
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,10 @@ File: README.info, Node: 089-pre, Next: 088, Up: Changelog
10851085
=============
10861086

10871087
*Fixes*
1088+
• Predicate ‘property’ when called with argument form ‘(property
1089+
"PROPERTY-NAME" :inherit t)’. (#460
1090+
(https://github.com/alphapapa/org-ql/issues/460). Thanks to
1091+
Stewmath (https://github.com/Stewmath) for reporting.)
10881092
• Reading of view settings from Org links in upcoming Emacs version.
10891093
(#461 (https://github.com/alphapapa/org-ql/issues/461). Thanks to
10901094
Ola Nilsson (https://github.com/snogge) for help debugging, and for
@@ -2069,49 +2073,49 @@ Node: Links38939
20692073
Node: Tips39626
20702074
Node: Changelog39950
20712075
Node: 089-pre40900
2072-
Node: 08841308
2073-
Node: 08742388
2074-
Node: 08643616
2075-
Node: 08543850
2076-
Node: 08444506
2077-
Node: 08344958
2078-
Node: 08245299
2079-
Node: 08145692
2080-
Node: 0846113
2081-
Node: 07448839
2082-
Node: 07349064
2083-
Node: 07249798
2084-
Node: 07150719
2085-
Node: 0751530
2086-
Node: 06354396
2087-
Node: 06254929
2088-
Node: 06155236
2089-
Node: 0655806
2090-
Node: 05258862
2091-
Node: 05159164
2092-
Node: 0559589
2093-
Node: 04961120
2094-
Node: 04861402
2095-
Node: 04761751
2096-
Node: 04662160
2097-
Node: 04562568
2098-
Node: 04462929
2099-
Node: 04363288
2100-
Node: 04263491
2101-
Node: 04163652
2102-
Node: 0463899
2103-
Node: 03268000
2104-
Node: 03168403
2105-
Node: 0368600
2106-
Node: 02371900
2107-
Node: 02272134
2108-
Node: 02172414
2109-
Node: 0272619
2110-
Node: 0176697
2111-
Node: Notes76798
2112-
Node: Comparison with Org Agenda searches76960
2113-
Node: org-sidebar77849
2114-
Node: License78128
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
21152119

21162120
End Tag Table
21172121

tests/test-org-ql.el

+9-1
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,15 @@ with keyword arg NOW in PLIST."
13371337

13381338
(org-ql-it "with a property and a value"
13391339
(org-ql-expect ('(property "agenda-group" "plans"))
1340-
'("Take over the universe" "Write a symphony"))))
1340+
'("Take over the universe" "Write a symphony")))
1341+
1342+
(org-ql-it "with a property and \"nil :inherit t\""
1343+
(org-ql-expect ('(property "agenda-group" nil :inherit t))
1344+
'("Take over the universe" "Take over the world" "Skype with president of Antarctica" "Take over Mars" "Visit Mars" "Take over the moon" "Visit the moon" "Practice leaping tall buildings in a single bound" "Renew membership in supervillain club" "Learn universal sign language" "Spaceship lease" "Recurring" "/r/emacs" "Shop for groceries" "Sunrise/sunset" "Write a symphony")))
1345+
1346+
(org-ql-it "with a property and \":inherit t\""
1347+
(org-ql-expect ('(property "agenda-group" :inherit t))
1348+
'("Take over the universe" "Take over the world" "Skype with president of Antarctica" "Take over Mars" "Visit Mars" "Take over the moon" "Visit the moon" "Practice leaping tall buildings in a single bound" "Renew membership in supervillain club" "Learn universal sign language" "Spaceship lease" "Recurring" "/r/emacs" "Shop for groceries" "Sunrise/sunset" "Write a symphony"))))
13411349

13421350
(describe "(regexp)"
13431351

0 commit comments

Comments
 (0)