-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skipping subtrees #3
Comments
Yeah, that should be easy enough. |
There, now you can do this: (org-ql (org-agenda-files)
(level 1))
;; or
(org-ql (org-agenda-files)
(level <= 2)) Does that do it? :) |
That is another feature I wanted to request, but what I meant was skipping to the next heading of the same or upper level when you reach a matching heading. For example, you may have a file that contains For example, is it possible to retrieve only
|
Well, I think I understand what you mean now. Although, do you mean that the root heading would also have a
I don't think it's easy, no. :) We can probably figure something out... |
Please reopen this issue. |
I guess what's needed to support this is to call a different next-heading function when the predicate matches. |
I just wondered if org-ql could be used to scan project as defined in this article. Actually, doing such scanning can be both complex and slow, so not supporting it at all might be a good idea.
Yeah, maybe you can add support for a custom skipping function as a filtering predicate, or maybe you don't need to support it. |
I have a prototype almost working, but due to the way the Org next-heading and end-of-subtree functions work, it's not as simple as it would seem... |
With that branch, you can do this:
And get these results: ((headline
(:raw-value "a" :begin 138 :end 146 :pre-blank 0 :contents-begin 147 :contents-end 147 :level 1 :priority nil :tags nil :todo-keyword
#("NEXT" 0 4
(fontified t line-prefix "" wrap-prefix
#("* " 0 2
(face org-indent))
face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 138 :title
(#("a" 0 1
(:parent #1)))))
(headline
(:raw-value "b" :begin 171 :end 179 :pre-blank 0 :contents-begin 180 :contents-end 180 :level 1 :priority nil :tags nil :todo-keyword
#("NEXT" 0 4
(fontified t line-prefix "" wrap-prefix
#("* " 0 2
(face org-indent))
face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 171 :title
(#("b" 0 1
(:parent #1)))))
(headline
(:raw-value "c.1" :begin 190 :end 201 :pre-blank 0 :contents-begin 202 :contents-end 202 :level 2 :priority nil :tags nil :todo-keyword
#("NEXT" 0 4
(fontified t line-prefix
#("*" 0 1
(face org-hide))
wrap-prefix
#("*** " 0 1
(face org-indent)
1 4
(face org-indent))
face org-todo))
:todo-type todo :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 190 :title
(#("c.1" 0 3
(:parent #1)))))) |
I think that might do it. What do you think? I'd like to benchmark it before merging it to master, to make sure that it doesn't make normal matching slower. I do want to keep speed up as much as possible, because I have some large Org files that I search with it, and little slowdowns add up. I also might simplify the API. Maybe it could have a query like: (without-children (todo "NEXT")) Or a |
It seems to work. Thank you. I thought of adding an option like Is it possible to add the feature as a predicate like |
Actually, it may be. I thought of another approach: rather than calling a different next-heading function when a match is found, the predicate could skip the rest of the subtree itself, then back up one character, and then the call to
Good point! I'm glad you are so familiar with my other projects. :) |
Ok, here's what I've come up with for a query API: (org-ql (current-buffer)
(skip-children (todo "NEXT"))) However, we could also do it like this, which might be better: (org-ql (org-agenda-files)
(when (todo "NEXT")
(skip-children))) It's a bit more verbose, but it feels more like elisp. Then again, I almost feel like it implies that it just skips things, rather than returning results. So maybe something like this would be better: (org-ql (current-buffer)
(skipping-children (todo "NEXT"))) Or: (org-ql (current-buffer)
(without-children (todo "NEXT"))) Or we could just do it as an argument, like: (org-ql (org-agenda-files)
(todo "NEXT")
:skip-children t) Which do you think is best? |
I personally prefer a query API that conforms to set theory (and SQL), so using
I also had the following ideas about this package, which were inspired by SQL:
These features can allow retrieving some (not all) items faster, especially if no sorting is enforced. Sorting is not needed at all if the target file is sorted beforehand. Org-mode has a builtin function for sorting entries, and I saw a user who uses the feature. It would be better if these features were implemented with the same predicate API. |
Single-clause
Probably, but I haven't experimented with complex expressions like that.
That would be easy, I think.
Why a separate function, rather than a limit of 1?
Sorting is already optional, of course.
I'm not sure what you mean here. |
That would be better.
You probably don't have to do that.
I thought of a function that can be used like a generator/iterator. It stops scanning the target file(s) when it reaches a heading that satisfies a given condition. It would be much faster than scanning the whole file but returning only one item. Actually, all I need may be a function that moves the point to a heading matching the predicate. |
The org-ql--filter-buffer function's loop could easily be extended to return a limited number of items. |
Thanks. I'll take a look at it.
|
This is not exactly what is asked for here, but it seems relevant: 479824f |
Thanks, it looks useful. I think the feature I requested at the beginning of this thread can be somehow implemented by filtering the result of As for the last topic, it is probably not a scope of this package. I think I'll implement a generator if I really need it. Thank you for the discussions above. I'll close this thread. |
It's okay, I have some ideas and I want to think about this some more. :) |
I implemented this feature in #89. |
I sometimes need only an overview of tasks in a file. For example, I might need only top-level headings of a file. org-agenda has
org-agenda-todo-list-sublevels
option (which is actually the default). Would you add an option to skip subtrees in org-ql (and org-agenda-ng)?The text was updated successfully, but these errors were encountered: