alphapapa / org-super-agenda

Supercharge your Org daily/weekly agenda by grouping items
GNU General Public License v3.0
1.37k stars 108 forks source link

org-super-agenda-keep-order breaks for auto groups #207

Open chasecaleb opened 3 years ago

chasecaleb commented 3 years ago

Using (setq org-super-agenda-keep-order t), introduced recently by !167, causes a backtrace with :auto-category or :auto-parent. I didn't test other :auto-* groups, but I'm guessing it's likely to be the case for all of them.

Example agenda view:

(setq org-agenda-custom-commands
      '(("nc" "Next: category" todo ""
         ((org-super-agenda-groups
           `((:auto-category t)))))))

Resulting backtrace when attempting to view it via C-c a n c (some sensitive data replaced with <redacted>):

Debugger entered--Lisp error: (wrong-type-argument buffer-or-string-p (:name "Category: work" :items ...))
  org-entries-lessp((:name "Category: work" :items ...) (:name "Category: prof..." :items ...))
  org-super-agenda--group-items((... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  org-super-agenda--filter-finalize-entries(#(<redacted>))
  org-agenda-finalize-entries((... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) todo)
  org-todo-list("")
  #f(compiled-function () #<bytecode 0xf90fd689e6a624d>)()
  funcall(#f(compiled-function () #<bytecode 0xf90fd689e6a624d>))
  (let ((org-super-agenda-groups '((:auto-category t)))) (funcall '#f(compiled-function () #<bytecode 0xf90fd689e6a624d>)))
  eval((let ((org-super-agenda-groups '((:auto-category t)))) (funcall '#f(compiled-function () #<bytecode 0xf90fd689e6a624d>))))
  org-agenda(nil)
  funcall-interactively(org-agenda nil)
  command-execute(org-agenda)

I don't think that this has anything to do with my org files or other config, but let me know if you need more info and I can provide it.


Context:

alphapapa commented 3 years ago

Thanks for reporting.

@Alexander-Miller Would you be able to take a look at this?

Alexander-Miller commented 3 years ago

Will do.

Alexander-Miller commented 3 years ago

Sorry for the late response, I had the grand idea to first work through whatever came up for my own packages before coming back to this bug ...

Anyway, I have a diagnosis, so now it is time to discuss the treatment. The problem is that due to the :auto-something selector you don't have a list of agenda entries that you can simply re-sort, but a list of lists - entries grouped by their parents, category etc.

There's 2 fixes I see:

  1. Check the super-agenda-groups for the presence of an :auto-* selector and if you find one re-sort every sublist individually. That's the technically correct, but more complex option. I also assume that the nesting won't go deeper than 1 level, otherwise it gets even more complex.
  2. Just don't do it. Only sort if you have a list of strings and document that keeping order won't work for :auto-* selectors. That's the path of least resistance and complexity, though someone might ask for option 1 later on (not me, I'm ok with this option)

I'm fine building either fix - what do you think @alphapapa ?

chasecaleb commented 2 years ago
  1. Check the super-agenda-groups for the presence of an :auto-* selector and if you find one re-sort every sublist individually. That's the technically correct, but more complex option. I also assume that the nesting won't go deeper than 1 level, otherwise it gets even more complex.

What about doing this recursively? That way it wouldn't be limited to just one level. I think that would be ideal if so.

chasecaleb commented 2 years ago

Hi @Alexander-Miller, are you still interested in fixing this or should someone else work on it?

Alexander-Miller commented 2 years ago

It's still on the agenda somewhere. I've just haven't been able to dedicate enough time to it since I'm struggling to fight off all the other issues that keep piling on day by day. But I do plan to have a go at this eventually.

chasecaleb commented 2 years ago

Understandable, thanks for the reply! If I get some spare time to prioritize it I'll try to work on this, but I'm in the same boat as you.

AndreaOrru commented 1 year ago

Is there any plan to fix this? Right now I'm just defining explicity groups instead of auto.

alphapapa commented 1 year ago

Yes, it is intended to be fixed when time permits.

@Alexander-Miller I'm guessing that recursively sorting the auto-grouped lists should work well enough, if you're still interested in implementing that.

Alexander-Miller commented 1 year ago

@alphapapa I am. I'll give it another go in the coming days.

Alexander-Miller commented 1 year ago

PR is up, recursive sorting seems to do the trick. Let me know if anything's amiss.

alphapapa commented 1 year ago

It's past time to tag a stable release of v1.3, which has several changes already, so I'm targeting this for v1.4.