alphapapa / org-ql

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.
GNU General Public License v3.0
1.35k stars 104 forks source link

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

Closed kofm closed 6 months ago

kofm commented 11 months ago

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 commented 11 months ago

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:

https://github.com/alphapapa/org-ql/blob/eb5377320fcfd38354d6e9e3e655969ae3c0e052/org-ql-view.el#L892-L896

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: https://github.com/alphapapa/org-ql/blob/eb5377320fcfd38354d6e9e3e655969ae3c0e052/org-ql-view.el#L822-L823

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=))
kofm commented 11 months ago

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 commented 11 months ago

You're welcome. Thanks for the kind words.

alphapapa commented 6 months ago

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 commented 6 months ago

Hello,

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