Add/Change: (--query-predicate) Move code to new function
This commit is contained in:
parent
2b0730d53b
commit
ac402e33c7
1 changed files with 62 additions and 58 deletions
74
org-ql.el
74
org-ql.el
|
|
@ -164,7 +164,45 @@ a list of defined `org-ql' sorting methods: `date', `deadline',
|
|||
(_ ; Buffer or string
|
||||
(list buffers-or-files))))
|
||||
((query preamble-re) (org-ql--query-preamble query))
|
||||
(predicate (byte-compile `(lambda ()
|
||||
(predicate (org-ql--query-predicate query))
|
||||
;; FIXME: Don't try to byte-compile already-compiled functions.
|
||||
(action (byte-compile action))
|
||||
;; TODO: Figure out how to use or reimplement the org-scanner-tags feature.
|
||||
;; (org-use-tag-inheritance t)
|
||||
;; (org-trust-scanner-tags t)
|
||||
(org-ql--today (org-today))
|
||||
(items (->> sources
|
||||
;; 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
|
||||
(unless (derived-mode-p 'org-mode)
|
||||
(user-error "Not an Org buffer: %s" (buffer-name)))
|
||||
(org-ql--select-cached :query query :preamble-re preamble-re
|
||||
:predicate predicate :action action :narrow narrow)))
|
||||
;; Flatten items
|
||||
(-flatten-n 1))))
|
||||
;; Sort items
|
||||
(pcase sort
|
||||
(`nil items)
|
||||
((guard (and sort
|
||||
(setq sort (-list sort))
|
||||
(cl-loop for elem in sort
|
||||
always (memq elem '(date deadline scheduled todo priority)))))
|
||||
;; Default sorting functions
|
||||
(org-ql--sort-by items sort))
|
||||
(_ (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)")))))
|
||||
|
||||
(defun org-ql--query-predicate (query)
|
||||
"Return predicate function for QUERY."
|
||||
(byte-compile `(lambda ()
|
||||
;; This is either really elegant or really ugly. Well, also
|
||||
;; possibly somewhere in-between. At the least, we should do
|
||||
;; this in a more flexible, abstracted way, but this will do
|
||||
|
|
@ -222,40 +260,6 @@ a list of defined `org-ql' sorting methods: `date', `deadline',
|
|||
(<= #'<=)
|
||||
(>= #'>=))
|
||||
,query))))))
|
||||
;; FIXME: Don't try to byte-compile already-compiled functions.
|
||||
(action (byte-compile action))
|
||||
;; TODO: Figure out how to use or reimplement the org-scanner-tags feature.
|
||||
;; (org-use-tag-inheritance t)
|
||||
;; (org-trust-scanner-tags t)
|
||||
(org-ql--today (org-today))
|
||||
(items (->> sources
|
||||
;; 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
|
||||
(unless (derived-mode-p 'org-mode)
|
||||
(user-error "Not an Org buffer: %s" (buffer-name)))
|
||||
(org-ql--select-cached :query query :preamble-re preamble-re
|
||||
:predicate predicate :action action :narrow narrow)))
|
||||
;; Flatten items
|
||||
(-flatten-n 1))))
|
||||
;; Sort items
|
||||
(pcase sort
|
||||
(`nil items)
|
||||
((guard (and sort
|
||||
(setq sort (-list sort))
|
||||
(cl-loop for elem in sort
|
||||
always (memq elem '(date deadline scheduled todo priority)))))
|
||||
;; Default sorting functions
|
||||
(org-ql--sort-by items sort))
|
||||
(_ (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)")))))
|
||||
|
||||
(defun org-ql--query-preamble (query)
|
||||
"Return (QUERY PREAMBLE) for QUERY.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue