Binding data before a predicate
- Lingua principale
- Emacs Lisp
- Stelle
- 1.6k
- Fork
- 120
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Happy new year! I've experimented with adding `org-ql` to `org-brain`, and it has been a huge performance boost. See commit here (if you're interested): https://github.com/Kungsgeten/org-brain/commit/31603865b4164b9f218cf2cb091cdb32e0d20aa2
I had an idea to provide `org-ql` predicates for some of `org-brain` specific things, in case users want to query their `org-brain` content. Here's an example:
```
(org-ql--defpred ob-child-of (entry-name)
"Return non-nil if current heading is an org-brain child of ENTRY-NAME."
(let ((children
(org-brain-children
(if-let ((entry (assoc entry-name
(mapcan #'org-brain--file-targets (org-brain-files)))))
(or (org-brain-entry-from-id (cdr entry))
(cdr entry))
(error "No entry found with name %s" entry-name)))))
(member (org-brain-entry-at-pt) children)))
```
This works, but is slow since the `let`-clause has to be run for every headline in the query. In reality the `let`-clause is only needed to be run once, before the search starts, and then the results could be used in each try.
It would be nice to have a way to bind data before the search starts, and have that data be available in the `defpred`. Perhaps something like this:
```
(org-ql--defpred ob-child-of (entry-name)
:let ((children
(org-brain-children
(if-let ((entry (assoc entry-name
(mapcan #'org-brain--file-targets (org-brain-files)))))
(or (org-brain-entry-from-id (cdr entry))
(cdr entry))
(error "No entry found with name %s" entry-name)))))
"Return non-nil if current heading is an org-brain child of ENTRY-NAME."
(member (org-brain-entry-at-pt) children))
```
It could be though that this won't be needed in any other use case, and thus doesn't fit into `org-ql`. Another posibility could be for the `BUFFERS-OR-FILES` argument in `org-ql-select` to also allow a list of markers to headlines.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.