Change: Rename --plain-query to --query-string-to-sexp

This commit is contained in:
Adam Porter 2020-11-22 12:22:22 -06:00
parent 3024f8bc9a
commit 8cf4e65ef0
5 changed files with 37 additions and 37 deletions

View file

@ -173,7 +173,7 @@ Is transformed into this query:
(interactive) (interactive)
(let ((buffers-files (with-current-buffer (helm-buffer-get) (let ((buffers-files (with-current-buffer (helm-buffer-get)
helm-org-ql-buffers-files)) helm-org-ql-buffers-files))
(query (org-ql--plain-query helm-pattern))) (query (org-ql--query-string-to-sexp helm-pattern)))
(helm-run-after-exit #'org-ql-search buffers-files query))) (helm-run-after-exit #'org-ql-search buffers-files query)))
;;;###autoload ;;;###autoload
@ -189,7 +189,7 @@ Is transformed into this query:
;; Expansion of `helm-build-sync-source' macro. ;; Expansion of `helm-build-sync-source' macro.
(helm-make-source name 'helm-source-sync (helm-make-source name 'helm-source-sync
:candidates (lambda () :candidates (lambda ()
(let* ((query (org-ql--plain-query helm-pattern)) (let* ((query (org-ql--query-string-to-sexp helm-pattern))
(window-width (window-width (helm-window)))) (window-width (window-width (helm-window))))
(when query (when query
(with-current-buffer (helm-buffer-get) (with-current-buffer (helm-buffer-get)

View file

@ -158,7 +158,7 @@ necessary."
;; Read sexp query. ;; Read sexp query.
(read query) (read query)
;; Parse non-sexp query into sexp query. ;; Parse non-sexp query into sexp query.
(org-ql--plain-query query))) (org-ql--query-string-to-sexp query)))
(list query))) (list query)))
(results (org-ql-select buffers-files query (results (org-ql-select buffers-files query
:action 'element-with-markers :action 'element-with-markers
@ -273,7 +273,7 @@ For example, an org-ql dynamic block header could look like:
#+BEGIN: org-ql :query (todo \"UNDERWAY\") :columns (priority todo heading) :sort (priority date) :ts-format \"%Y-%m-%d %H:%M\"" #+BEGIN: org-ql :query (todo \"UNDERWAY\") :columns (priority todo heading) :sort (priority date) :ts-format \"%Y-%m-%d %H:%M\""
(-let* (((&plist :query :columns :sort :ts-format :take) params) (-let* (((&plist :query :columns :sort :ts-format :take) params)
(query (cl-etypecase query (query (cl-etypecase query
(string (org-ql--plain-query query)) (string (org-ql--query-string-to-sexp query))
(list ;; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code. (list ;; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code.
(org-ql--ask-unsafe-query query) (org-ql--ask-unsafe-query query)
query))) query)))

View file

@ -772,7 +772,7 @@ When opened, the link searches the buffer it's opened from."
;; Read sexp query. ;; Read sexp query.
(read query) (read query)
;; Parse non-sexp query into sexp query. ;; Parse non-sexp query into sexp query.
(org-ql--plain-query query))))) (org-ql--query-string-to-sexp query)))))
(define-infix-command org-ql-view--transient-in () (define-infix-command org-ql-view--transient-in ()
:description (lambda () (org-ql-view--format-transient-lisp-argument "In buffers/files" org-ql-view-buffers-files)) :description (lambda () (org-ql-view--format-transient-lisp-argument "In buffers/files" org-ql-view-buffers-files))

View file

@ -196,8 +196,8 @@ See Info node `(org-ql)Queries'."
;; the function correctly, apparently because `org-ql-predicates' ;; the function correctly, apparently because `org-ql-predicates'
;; ends up being not defined correctly at expansion time. ;; ends up being not defined correctly at expansion time.
(defun org-ql--def-plain-query-fn () (defun org-ql--def-query-string-to-sexp-fn ()
"Define function `org-ql--plain-query'. "Define function `org-ql--query-string-to-sexp'.
Builds the PEG expression using predicates defined in Builds the PEG expression using predicates defined in
`org-ql-predicates' and `org-ql-predicates-extra-aliases'." `org-ql-predicates' and `org-ql-predicates-extra-aliases'."
(let* ((predicates (--map (symbol-name (plist-get (cdr it) :name)) (let* ((predicates (--map (symbol-name (plist-get (cdr it) :name))
@ -214,7 +214,7 @@ Builds the PEG expression using predicates defined in
;; obscure bug in `peg': when one keyword is a substring of another, ;; obscure bug in `peg': when one keyword is a substring of another,
;; and the shorter one is listed first, the shorter one fails to match. ;; and the shorter one is listed first, the shorter one fails to match.
(-sort (-on #'> #'length))))) (-sort (-on #'> #'length)))))
(fset 'org-ql--plain-query (fset 'org-ql--query-string-to-sexp
(byte-compile (byte-compile
`(cl-function `(cl-function
(lambda (input &optional (boolean 'and)) (lambda (input &optional (boolean 'and))
@ -361,8 +361,8 @@ match."
preambles))) preambles)))
`(progn `(progn
(cl-eval-when (compile load eval) (cl-eval-when (compile load eval)
;; When compiling, the predicate must be added to `org-ql-predicates' before `org-ql--def-plain-query-fn' ;; When compiling, the predicate must be added to `org-ql-predicates' before `org-ql--def-query-string-to-sexp-fn'
;; is called to define `org-ql--plain-query'. Otherwise, `org-ql--plain-query' seems to work properly ;; is called to define `org-ql--query-string-to-sexp'. Otherwise, `org-ql--query-string-to-sexp' seems to work properly
;; when interpreted but not always when the file is byte-compiled. ;; when interpreted but not always when the file is byte-compiled.
(setf (map-elt org-ql-predicates ',predicate-name) (setf (map-elt org-ql-predicates ',predicate-name)
`(:name ,',name :aliases ,',aliases :fn ,',fn-name :docstring ,,docstring :args ,',args `(:name ,',name :aliases ,',aliases :fn ,',fn-name :docstring ,,docstring :args ,',args
@ -371,7 +371,7 @@ match."
(org-ql--define-normalize-query (reverse org-ql-predicates)) (org-ql--define-normalize-query (reverse org-ql-predicates))
;; NOTE: Reversing is important! ;; NOTE: Reversing is important!
(org-ql--define-preamble-fn (reverse org-ql-predicates)) (org-ql--define-preamble-fn (reverse org-ql-predicates))
(org-ql--def-plain-query-fn)) (org-ql--def-query-string-to-sexp-fn))
(cl-defun ,fn-name ,args ,docstring ,predicate))))) (cl-defun ,fn-name ,args ,docstring ,predicate)))))
;; TODO: Mark as obsolete/deprecated. ;; TODO: Mark as obsolete/deprecated.
@ -1747,7 +1747,7 @@ of the line after the heading."
;; Generally it shouldn't matter, but it might... ;; Generally it shouldn't matter, but it might...
(org-ql--define-normalize-query (reverse org-ql-predicates)) (org-ql--define-normalize-query (reverse org-ql-predicates))
(org-ql--define-preamble-fn (reverse org-ql-predicates)) (org-ql--define-preamble-fn (reverse org-ql-predicates))
(org-ql--def-plain-query-fn)) (org-ql--def-query-string-to-sexp-fn))
;;;;; Sorting ;;;;; Sorting

View file

@ -327,60 +327,60 @@ RESULTS should be a list of strings as returned by
;; TODO: Other predicates. ;; TODO: Other predicates.
(it "Negated terms" (it "Negated terms"
(expect (org-ql--plain-query "todo: !todo:CHECK,SOMEDAY") (expect (org-ql--query-string-to-sexp "todo: !todo:CHECK,SOMEDAY")
:to-equal '(and (todo) (not (todo "CHECK" "SOMEDAY")))) :to-equal '(and (todo) (not (todo "CHECK" "SOMEDAY"))))
(expect (org-ql--plain-query "!todo:CHECK,SOMEDAY todo:") (expect (org-ql--query-string-to-sexp "!todo:CHECK,SOMEDAY todo:")
:to-equal '(and (not (todo "CHECK" "SOMEDAY")) (todo))) :to-equal '(and (not (todo "CHECK" "SOMEDAY")) (todo)))
(expect (org-ql--plain-query "tags:universe !moon") (expect (org-ql--query-string-to-sexp "tags:universe !moon")
:to-equal '(and (tags "universe") (not (regexp "moon")))) :to-equal '(and (tags "universe") (not (regexp "moon"))))
(expect (org-ql--plain-query "!moon tags:universe") (expect (org-ql--query-string-to-sexp "!moon tags:universe")
:to-equal '(and (not (regexp "moon")) (tags "universe"))) :to-equal '(and (not (regexp "moon")) (tags "universe")))
(expect (org-ql--plain-query "mars !ts:on=today") (expect (org-ql--query-string-to-sexp "mars !ts:on=today")
:to-equal '(and (regexp "mars") (not (ts :on "today")))) :to-equal '(and (regexp "mars") (not (ts :on "today"))))
(expect (org-ql--plain-query "!\"quoted phrase\"") (expect (org-ql--query-string-to-sexp "!\"quoted phrase\"")
:to-equal '(not (regexp "quoted phrase")))) :to-equal '(not (regexp "quoted phrase"))))
(it "Regexp predicates" (it "Regexp predicates"
(expect (org-ql--plain-query "scheduled") (expect (org-ql--query-string-to-sexp "scheduled")
;; No colon after keyword, so not a predicate query. ;; No colon after keyword, so not a predicate query.
:to-equal '(regexp "scheduled")) :to-equal '(regexp "scheduled"))
(expect (org-ql--plain-query "\"quoted phrase\"") (expect (org-ql--query-string-to-sexp "\"quoted phrase\"")
:to-equal '(regexp "quoted phrase")) :to-equal '(regexp "quoted phrase"))
(expect (org-ql--plain-query "regexp:word") (expect (org-ql--query-string-to-sexp "regexp:word")
:to-equal '(regexp "word")) :to-equal '(regexp "word"))
(expect (org-ql--plain-query "regexp:\"quoted phrase\"") (expect (org-ql--query-string-to-sexp "regexp:\"quoted phrase\"")
:to-equal '(regexp "quoted phrase"))) :to-equal '(regexp "quoted phrase")))
(it "Timestamp-based predicates" (it "Timestamp-based predicates"
(expect (org-ql--plain-query "scheduled:on=2017-07-07") (expect (org-ql--query-string-to-sexp "scheduled:on=2017-07-07")
:to-equal '(scheduled :on "2017-07-07")) :to-equal '(scheduled :on "2017-07-07"))
(expect (org-ql--plain-query "deadline:from=2017-07-07,to=2017-07-09") (expect (org-ql--query-string-to-sexp "deadline:from=2017-07-07,to=2017-07-09")
:to-equal '(deadline :from "2017-07-07" :to "2017-07-09")) :to-equal '(deadline :from "2017-07-07" :to "2017-07-09"))
(expect (org-ql--plain-query "planning:from=2017-07-07") (expect (org-ql--query-string-to-sexp "planning:from=2017-07-07")
:to-equal '(planning :from "2017-07-07")) :to-equal '(planning :from "2017-07-07"))
(expect (org-ql--plain-query "closed:from=2017-07-07") (expect (org-ql--query-string-to-sexp "closed:from=2017-07-07")
:to-equal '(closed :from "2017-07-07")) :to-equal '(closed :from "2017-07-07"))
(expect (org-ql--plain-query "ts-active:to=2017-07-07") (expect (org-ql--query-string-to-sexp "ts-active:to=2017-07-07")
:to-equal '(ts-active :to "2017-07-07")) :to-equal '(ts-active :to "2017-07-07"))
(expect (org-ql--plain-query "ts-inactive:to=2017-07-07") (expect (org-ql--query-string-to-sexp "ts-inactive:to=2017-07-07")
:to-equal '(ts-inactive :to "2017-07-07")) :to-equal '(ts-inactive :to "2017-07-07"))
(expect (org-ql--plain-query "ts-a:to=2017-07-07") (expect (org-ql--query-string-to-sexp "ts-a:to=2017-07-07")
:to-equal '(ts-a :to "2017-07-07")) :to-equal '(ts-a :to "2017-07-07"))
(expect (org-ql--plain-query "ts-i:on=2017-07-07") (expect (org-ql--query-string-to-sexp "ts-i:on=2017-07-07")
:to-equal '(ts-i :on "2017-07-07")) :to-equal '(ts-i :on "2017-07-07"))
(expect (org-ql--plain-query "ts:") (expect (org-ql--query-string-to-sexp "ts:")
:to-equal '(ts)) :to-equal '(ts))
(expect (org-ql--plain-query "clocked:") (expect (org-ql--query-string-to-sexp "clocked:")
:to-equal '(clocked))) :to-equal '(clocked)))
(it "To-do predicates" (it "To-do predicates"
(expect (org-ql--plain-query "todo:") (expect (org-ql--query-string-to-sexp "todo:")
:to-equal '(todo)) :to-equal '(todo))
(expect (org-ql--plain-query "todo:TODO") (expect (org-ql--query-string-to-sexp "todo:TODO")
:to-equal '(todo "TODO")) :to-equal '(todo "TODO"))
(expect (org-ql--plain-query "todo:TODO,SOMEDAY") (expect (org-ql--query-string-to-sexp "todo:TODO,SOMEDAY")
:to-equal '(todo "TODO" "SOMEDAY"))) :to-equal '(todo "TODO" "SOMEDAY")))
(it "Compound queries" (it "Compound queries"
(expect (org-ql--plain-query "todo:SOMEDAY ts-a:from=2020-01-01,to=2021-01-01") (expect (org-ql--query-string-to-sexp "todo:SOMEDAY ts-a:from=2020-01-01,to=2021-01-01")
:to-equal '(and (todo "SOMEDAY") (ts-a :from "2020-01-01" :to "2021-01-01"))) :to-equal '(and (todo "SOMEDAY") (ts-a :from "2020-01-01" :to "2021-01-01")))
(expect (org-ql--plain-query "regexp:\"quoted phrase\" todo:SOMEDAY") (expect (org-ql--query-string-to-sexp "regexp:\"quoted phrase\" todo:SOMEDAY")
:to-equal '(and (regexp "quoted phrase") (todo "SOMEDAY"))))) :to-equal '(and (regexp "quoted phrase") (todo "SOMEDAY")))))
(describe "Convert sexp queries to non-sexp queries" (describe "Convert sexp queries to non-sexp queries"