Skip to content
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

Grouping the output of org-ql-search by category #363

Closed
kofm opened this issue Aug 1, 2023 · 5 comments
Closed

Grouping the output of org-ql-search by category #363

kofm opened this issue Aug 1, 2023 · 5 comments

Comments

@kofm
Copy link

kofm commented Aug 1, 2023

Hello,

Firstly, I would like to express my appreciation for this incredible package!

I am currently experiencing an issue with using :super-groups to group the output of my queries by category. I'm not sure if this is due to an error on my part, or if it's a bug in the system.

Steps to reproduce:

I created a minimal reproducible example in test.org as follows:

* Title
** TODO Test
:PROPERTIES:
:CATEGORY:Test
:END:

I ran the following query:

(org-ql-search  "/tmp/test.org" '(todo "TODO")  :super-groups '((:name "test" :category "test")))

Expected Result:

I expected the output to be grouped by the category "Test".

Actual Result:

The output was not grouped as expected. Here is a screenshot of the result:

image

When I used :auto-category t as :super-groups, it worked as expected:

(org-ql-search  "/tmp/test.org" '(todo "TODO") :super-groups '((:auto-category t)))

image

Could you kindly assist me in understanding if this is a bug or if there is a mistake in my usage of the :super-groups option?

Thank you for your time and assistance.

@alphapapa
Copy link
Owner

Hello,

Thanks for the kind words. I'm glad this is useful to you.

The issue here is that the org-category text property is not added to the string:

org-ql/org-ql-view.el

Lines 892 to 896 in eb53773

(org-add-props it properties
'org-agenda-type 'search
'todo-state todo-keyword
'tags tag-list
'org-habit-p habit-property)))))

Which is what org-super-agenda looks in to find the category:

https://github.com/alphapapa/org-super-agenda/blob/f4f528985397c833c870967884b013cf91a1da4a/org-super-agenda.el#L288-L290

Probably org-ql-view--format-element should add the category to match the behavior of org-agenda-format-item. You can see in this comment:

org-ql/org-ql-view.el

Lines 822 to 823 in eb53773

;; This essentially needs to do what `org-agenda-format-item' does,
;; which is a lot. We are a long way from that, but it's a start.

Using the auto-group works because, for whatever reason, the code as-is gets the category differently than the non-auto-group selector, without requiring the text property:

https://github.com/alphapapa/org-super-agenda/blob/f4f528985397c833c870967884b013cf91a1da4a/org-super-agenda.el#L1035-L1038

So this problem could also be worked around by changing the category group selector in org-super-agenda.

Until I have time to fix this, you could add this code to your Emacs configuration, which should make it work:

(org-super-agenda--defgroup category
  "Group items that match any of the given categories.
Argument may be a string or list of strings."
  :section-name (concat "Items categorized as: " (s-join " OR " args))
  :test (cl-member (or (org-super-agenda--get-category item)
                       (org-super-agenda--when-with-marker-buffer (org-super-agenda--get-marker item)
                         (org-get-category)))
                   args :test #'string=))

@alphapapa alphapapa self-assigned this Aug 1, 2023
@alphapapa alphapapa added this to the 0.8 milestone Aug 1, 2023
@kofm
Copy link
Author

kofm commented Aug 2, 2023

Hello,

I just wanted to extend my deepest gratitude for your prompt, detailed, and helpful response. I applied the provided workaround to my Emacs configuration, and it works perfectly! Your dedication to maintaining this package and assisting its users is remarkable.

Thank you so much for your time, effort, and kind words. I appreciate it!

@alphapapa
Copy link
Owner

You're welcome. Thanks for the kind words.

@alphapapa
Copy link
Owner

Hi again Gabriele,

I've pushed a fix for this to master so that entries in an org-ql-view buffer now include the org-category text property like in Org Agenda buffers. The workaround of redefining the org-super-agenda :category selector shouldn't be necessary anymore.

If you have time, would you mind testing this and letting me know if it solves the problem sans-workaround for you?

Thanks.

@kofm
Copy link
Author

kofm commented Dec 26, 2023

Hello,

Everything now works as expected without the workaround. Thank you for your support in resolving this issue and all your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants