Change: (org-ql-query) Simplify
This commit is contained in:
parent
ac402e33c7
commit
3133c4f33b
1 changed files with 13 additions and 17 deletions
30
org-ql.el
30
org-ql.el
|
|
@ -158,11 +158,18 @@ SORT is either nil, in which case items are not sorted; or one or
|
||||||
a list of defined `org-ql' sorting methods: `date', `deadline',
|
a list of defined `org-ql' sorting methods: `date', `deadline',
|
||||||
`scheduled', `todo', and `priority'."
|
`scheduled', `todo', and `priority'."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(-let* ((sources (pcase buffers-or-files
|
(-let* ((buffers (->> (cl-typecase buffers-or-files
|
||||||
(`nil (list (current-buffer)))
|
(null (list (current-buffer)))
|
||||||
((pred listp) buffers-or-files)
|
(list buffers-or-files)
|
||||||
(_ ; Buffer or string
|
(otherwise (list buffers-or-files)))
|
||||||
(list buffers-or-files))))
|
(--map (cl-etypecase it
|
||||||
|
(buffer it)
|
||||||
|
(string (or (find-buffer-visiting it)
|
||||||
|
(when (file-readable-p it)
|
||||||
|
;; It feels unintuitive that `find-file-noselect' returns
|
||||||
|
;; a buffer if the filename doesn't exist.
|
||||||
|
(find-file-noselect it))
|
||||||
|
(user-error "Can't open file: %s" it)))))))
|
||||||
((query preamble-re) (org-ql--query-preamble query))
|
((query preamble-re) (org-ql--query-preamble query))
|
||||||
(predicate (org-ql--query-predicate query))
|
(predicate (org-ql--query-predicate query))
|
||||||
;; FIXME: Don't try to byte-compile already-compiled functions.
|
;; FIXME: Don't try to byte-compile already-compiled functions.
|
||||||
|
|
@ -171,23 +178,12 @@ a list of defined `org-ql' sorting methods: `date', `deadline',
|
||||||
;; (org-use-tag-inheritance t)
|
;; (org-use-tag-inheritance t)
|
||||||
;; (org-trust-scanner-tags t)
|
;; (org-trust-scanner-tags t)
|
||||||
(org-ql--today (org-today))
|
(org-ql--today (org-today))
|
||||||
(items (->> sources
|
(items (->> buffers
|
||||||
;; List buffers
|
|
||||||
(--map (cl-etypecase it
|
|
||||||
(buffer it)
|
|
||||||
(string (or (find-buffer-visiting it)
|
|
||||||
(when (file-readable-p it)
|
|
||||||
;; It feels unintuitive that `find-file-noselect' returns
|
|
||||||
;; a buffer if the filename doesn't exist.
|
|
||||||
(find-file-noselect it))
|
|
||||||
(user-error "Can't open file: %s" it)))))
|
|
||||||
;; Filter buffers (i.e. select items)
|
|
||||||
(--map (with-current-buffer it
|
(--map (with-current-buffer it
|
||||||
(unless (derived-mode-p 'org-mode)
|
(unless (derived-mode-p 'org-mode)
|
||||||
(user-error "Not an Org buffer: %s" (buffer-name)))
|
(user-error "Not an Org buffer: %s" (buffer-name)))
|
||||||
(org-ql--select-cached :query query :preamble-re preamble-re
|
(org-ql--select-cached :query query :preamble-re preamble-re
|
||||||
:predicate predicate :action action :narrow narrow)))
|
:predicate predicate :action action :narrow narrow)))
|
||||||
;; Flatten items
|
|
||||||
(-flatten-n 1))))
|
(-flatten-n 1))))
|
||||||
;; Sort items
|
;; Sort items
|
||||||
(pcase sort
|
(pcase sort
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue