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

Extra Priority Values (A-Z and 0-64) #313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ComedyTomedy
Copy link

Sort order is letters first, then numbers. I'm not particularly attached to that, just made a choice. Org docs don't seem to define how they interrelate when mixed.

Also renamed priority "letters" to "values" in variable names & docs. Since this added a lot of noise, here's the important change:

(let* ((priority-values (append (mapcar #'string (number-sequence 65 (+ 65 25)))
                                (mapcar #'number-to-string (number-sequence 0 64))))

@alphapapa
Copy link
Owner

Hello,

Yes, this is probably something that needs to be addressed. But if we're going to do it, we should probably try to adhere as closely as possible to how Org does it, i.e. to be sure to accept all of the kinds of values that it accepts. Would you do a little research about what Org officially allows now? IIRC it's changed slightly in the past few major releases, or something like that.

As well, if we change what priority values are accepted, we should ensure that the priority sorter works with the new values. And it might be a good idea to revisit the priority-related tests to be sure that at least one value of each type is tested for. Would you be interested in working on those issues too?

Thanks.

@ComedyTomedy
Copy link
Author

ComedyTomedy commented Nov 25, 2022

Thanks for the quick reply! I need to fix some silly mistakes in my code anyway - I don't use git much but it looks like I can keep tweaking my branch and the PR will be updated automatically. I'm busy for a few days but will try to fix my mistakes & get the priority sorter working next week (I thought it worked; didn't test a wide-enough range of values).

Sorting in the order 0-64, then ?A-?Z will match what org does (in Emacs 28.1 at least), both in C-c ^ and org-agenda. Emacs Docs say numeric priorities go up to 64 (which is (1- ?A), thus makes sense). They specify no minimum value, but [#0] works. Numerical values outside 0-99 don't. The function #'org-priority-to-value also does "0-64, ?A-?Z".

Org Elements API doesn't seem to agree (for now?), and for [#​0] to [#​9] returns ?0 to ?9 (which is 48-57), but for [#%] it returns ?%, so it's clearly just converting a string to a char.

I'm unfamiliar with testing / buttercup, so might not be able to add tests confidently.

@alphapapa
Copy link
Owner

Thanks for the quick reply! I need to fix some silly mistakes in my
code anyway - I don't use git much but it looks like I can keep
tweaking my branch and the PR will be updated automatically. I'm busy
for a few days but will try to fix my mistakes & get the priority
sorter working next week (I thought it worked; didn't test a
wide-enough range of values).

No problem. As you can see, there's a backlog of issues and PRs; I haven't had as much time lately to work on this package as I would like.

When you update your branch, you should generally rebase it on top of current master and then force-push. And unless your commit history matters, or unless you're separating commits for readability, feel free to squash the commits, which makes it easier to review.

Sorting in the order 0-64, then ?A-?Z will match what org does (in
Emacs 28.1 at least), both in C-c ^ and org-agenda. Emacs Docs say
numeric priorities go up to 64 (which is (1- ?A), thus makes
sense). They specify no minimum value, but [#0] works. Numerical
values outside 0-99 don't. The function #'org-priority-to-value also
does "0-64, ?A-?Z".

Sounds good.

Org Elements API doesn't seem to agree (for now?), and for [#​0] to
[#​9] returns ?0 to ?9 (which is 48-57), but for [#%] it returns ?%, so
it's clearly just converting a string to a char.

Hm, we might want to look at that more closely. Also, Org 9.6 just came out--is that what you looked at?

I'm unfamiliar with testing / buttercup, so might not be able to add
tests confidently.

No problem. Buttercup is pretty simple, and it's well-documented, but I can help you with it. Probably we'll need to tweak a few priorities in the test data file to give us something to test against.

Thanks.

@alphapapa alphapapa force-pushed the master branch 2 times, most recently from 059b10c to 77b4c2b Compare December 16, 2023 13:55
@ComedyTomedy ComedyTomedy force-pushed the extra-prio-values branch 3 times, most recently from 94a7a44 to e6bde30 Compare October 11, 2024 00:40
@ComedyTomedy
Copy link
Author

Looking back at this... Prios 0-9 and A-Z work fine, but comparison and sorting are broken for 10-64. It's still an improvement on current behavior, but maybe worth someone more knowledgeable doing a thorough job!

@alphapapa
Copy link
Owner

Looking back at this... Prios 0-9 and A-Z work fine, but comparison and sorting are broken for 10-64. It's still an improvement on current behavior, but maybe worth someone more knowledgeable doing a thorough job!

Thanks for coming back to this. This is a good first step, but I wouldn't be able to merge this until the problems you mentioned are fixed. But neither of those should be difficult, so if you're interested, I encourage you to work on that, too. My time is limited, but I'll be glad to advise you as I can.

Expand recognised priority values from A-C to current org-mode
standard of A-Z and 0-64.
@ComedyTomedy
Copy link
Author

OK! I've updated the regex builder in org-ql-defpred priority / :preambles, but I'm not sure what that does! Seems to work, but I can't test in-situe without understanding when it's called.

Sorting and comparison are now working, unless there are edge cases that I've not checked (very possible!). Can't figure out buttercup, eval-buffer in test-org-ql.el just messages "Buttercup test failed". I'm probably using it wrong.

@alphapapa
Copy link
Owner

Sorting and comparison are now working, unless there are edge cases that I've not checked (very possible!). Can't figure out buttercup, eval-buffer in test-org-ql.el just messages "Buttercup test failed". I'm probably using it wrong.

The tests are run using the makem.sh file. You might like to use https://github.com/alphapapa/makem.sh/blob/master/makem.el to run it from a menu.

@ComedyTomedy
Copy link
Author

Added tests, feel confident that this is the final force-push! All your help and encouragement is much appreciated :)

@alphapapa
Copy link
Owner

Thanks, I think we're close to being done here. A few more items to consider:

  • Have you done the FSF copyright assignment for Emacs? We're planning to upstream parts of Org QL into Org, and this is no longer a "tinychange" patch.
  • I feel like the sorting of priorities needs to be tested.
  • One reason I think the priority sorting should be tested is that I don't know what it is supposed to be with the new changes, i.e. if I have items with priorities A, 0, B, 50, and Z, in what order do they sort?

Thanks for your work on this.

@ComedyTomedy
Copy link
Author

Started the copyright assignment process.

From the docs, it seems that sort-order of mixed numbers and letters is intentionally undefined, and users are expected to stick to either alphabetic or numerical priorities. So technically all that matters is that prios 0-64 sort correctly, and that A-Z sort correctly. Since the numerical values of A-Z continue from 65 upwards, I think sorting 0-64 then A-Z makes sense, because it's the easiest behaviour and gets all defined cases right.

We can't really base this on existing behavior because org-sort-elements doesn't work with numeric priorities yet — it uses string-to-char to convert prios to values (as does org-element API), so it "sees" [#​50] as identical to [#​5] or even [#​5foo]. I'd consider this a bug. I guess the next step is to report it and see who agrees with me.

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

Successfully merging this pull request may close these issues.

2 participants