Tidy: (org-ql-sparse-tree) Docstring; use pcase

This commit is contained in:
Adam Porter 2023-03-10 04:44:05 -06:00
parent 1ae2f0cd60
commit 99e580b530

View file

@ -93,7 +93,7 @@ directories, etc, which would make it slow to list the
The tree will show the lines where the query matches, and any The tree will show the lines where the query matches, and any
other context defined in `org-show-context-detail', which see. other context defined in `org-show-context-detail', which see.
QUERY: An `org-ql' query in either sexp or non-sexp form (see QUERY is an `org-ql' query in either sexp or string form (see
Info node `(org-ql)Queries'). Info node `(org-ql)Queries').
When KEEP-PREVIOUS is non-nil (interactively, with prefix), the When KEEP-PREVIOUS is non-nil (interactively, with prefix), the
@ -111,14 +111,17 @@ Runs `org-occur-hook' after making the sparse tree."
(org-remove-occur-highlights nil nil t) (org-remove-occur-highlights nil nil t)
(org-overview)) (org-overview))
(let ((num-results 0) (let ((num-results 0)
(query (cl-etypecase query (query (pcase-exhaustive query
(string (if (or (string-prefix-p "(" query) ((and (pred stringp)
(string-prefix-p "\"" query)) (rx bos (0+ blank) (or "(" "\"")))
;; Read sexp query. ;; Read sexp query from string.
(read query) (read query))
;; Parse non-sexp query into sexp query. ((pred stringp)
(org-ql--query-string-to-sexp query))) ;; Parse string query into sexp query.
(list query)))) (org-ql--query-string-to-sexp query))
((pred listp)
;; Sexp query.
query))))
;; FIXME: Accept plain queries as well. ;; FIXME: Accept plain queries as well.
(org-ql-select buffer query (org-ql-select buffer query
:action (lambda () :action (lambda ()