This commit is contained in:
tumashu 2020-11-22 15:59:41 +08:00 committed by GitHub
commit d5d4cc6e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -75,6 +75,8 @@ Installing with [[https://framagit.org/steckerhalter/quelpa][Quelpa]] is easy:
# These links work on GitHub's Org renderer but not in Org. # These links work on GitHub's Org renderer but not in Org.
If user search bare string, the predicate ~org-ql-plain-string-predicate~ will be used by default.
Feedback on these APIs is welcome. Eventually, after being tested and polished, they will be considered stable. Feedback on these APIs is welcome. Eventually, after being tested and polished, they will be considered stable.
# TODO: Find a way to get these examples included in the info manual. # TODO: Find a way to get these examples included in the info manual.
@ -531,6 +533,8 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
/Note:/ The next release, 0.5, may include changes which will require minor updates to written queries (e.g. a few predicates may be renamed). Users who wish to avoid those changes happening unexpectedly in their configs should avoid upgrading =org-ql= beyond 0.4 automatically, as they will be pushed to the =master= branch when ready. /Note:/ The next release, 0.5, may include changes which will require minor updates to written queries (e.g. a few predicates may be renamed). Users who wish to avoid those changes happening unexpectedly in their configs should avoid upgrading =org-ql= beyond 0.4 automatically, as they will be pushed to the =master= branch when ready.
*Added* *Added*
+ *Variable*
- ~org-ql-plain-string-predicate~, which will be used when user search bare string.
+ *Commands* + *Commands*
- ~helm-org-ql-views~, which shows one of ~org-ql-views~ selected with Helm. - ~helm-org-ql-views~, which shows one of ~org-ql-views~ selected with Helm.
- ~org-ql-search~ can search files in ~org-directory~; customization options are available in the ~org-ql-search~ group. - ~org-ql-search~ can search files in ~org-directory~; customization options are available in the ~org-ql-search~ group.

View file

@ -129,6 +129,9 @@ the value returned by it at that node.")
"Plist of predicates, their corresponding functions, and their docstrings. "Plist of predicates, their corresponding functions, and their docstrings.
This list should not contain any duplicates.")) This list should not contain any duplicates."))
(defvar org-ql-plain-string-predicate 'regexp
"Plain strings in queries are matched with this predicate.")
;;;; Customization ;;;; Customization
(defgroup org-ql nil (defgroup org-ql nil
@ -588,8 +591,9 @@ Or, when possible, fix the problem."
(defun org-ql--pre-process-query (query) (defun org-ql--pre-process-query (query)
"Return QUERY having been pre-processed. "Return QUERY having been pre-processed.
Replaces bare strings with (regexp) selectors, and appropriate Replaces bare strings with predicate set by
`ts'-related selectors." `org-ql-plain-string-predicate' , and appropriate `ts'-related
selectors."
;; This is unsophisticated, but it works. ;; This is unsophisticated, but it works.
;; TODO: Maybe query pre-processing should be done in one place, ;; TODO: Maybe query pre-processing should be done in one place,
;; rather than here and in --query-predicate. ;; rather than here and in --query-predicate.
@ -605,7 +609,7 @@ Replaces bare strings with (regexp) selectors, and appropriate
(`(unless ,condition . ,clauses) `(unless ,(rec condition) (`(unless ,condition . ,clauses) `(unless ,(rec condition)
,@(mapcar #'rec clauses))) ,@(mapcar #'rec clauses)))
;; TODO: Combine (regexp) when appropriate (i.e. inside an OR, not an AND). ;; TODO: Combine (regexp) when appropriate (i.e. inside an OR, not an AND).
((pred stringp) `(regexp ,element)) ((pred stringp) `(,org-ql-plain-string-predicate ,element))
;; Quote children queries so the user doesn't have to. ;; Quote children queries so the user doesn't have to.
(`(children ,query) `(children ',query)) (`(children ,query) `(children ',query))
(`(children) '(children (lambda () t))) (`(children) '(children (lambda () t)))
@ -1776,7 +1780,8 @@ Builds the PEG expression using predicates defined in
(-sort (-on #'> #'length))))) (-sort (-on #'> #'length)))))
`(cl-defun org-ql--plain-query (input &optional (boolean 'and)) `(cl-defun org-ql--plain-query (input &optional (boolean 'and))
"Return query parsed from plain query string INPUT. "Return query parsed from plain query string INPUT.
Multiple predicates are combined with BOOLEAN." Multiple predicates are combined with BOOLEAN.
If no predicates are found, `org-ql-plain-string-predicate' will be used."
(unless (s-blank-str? input) (unless (s-blank-str? input)
(let* ((query (org-ql--peg-parse-string (let* ((query (org-ql--peg-parse-string
((query (+ term ((query (+ term
@ -1787,7 +1792,7 @@ Multiple predicates are combined with BOOLEAN."
positive-term)) positive-term))
(positive-term (or (and predicate-with-args `(pred args -- (cons (intern pred) args))) (positive-term (or (and predicate-with-args `(pred args -- (cons (intern pred) args)))
(and predicate-without-args `(pred -- (list (intern pred)))) (and predicate-without-args `(pred -- (list (intern pred))))
(and plain-string `(s -- (list 'regexp s))))) (and plain-string `(s -- (list org-ql-plain-string-predicate s)))))
(plain-string (or quoted-arg unquoted-arg)) (plain-string (or quoted-arg unquoted-arg))
(predicate-with-args (substring predicate) ":" args) (predicate-with-args (substring predicate) ":" args)
(predicate-without-args (substring predicate) ":") (predicate-without-args (substring predicate) ":")