emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tommy Jollyboat <jollyboatbros@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] Numeric priorities only partially supported
Date: Sun, 13 Oct 2024 17:02:04 +0100	[thread overview]
Message-ID: <CANDZv_N394TYMy30-KuEQV+eZ0FEkm4GSjTrkUtDViK_-DkX-Q@mail.gmail.com> (raw)

(tested with Org 9.7.11, I've done my best to search archives and the
bug-tracker)

Back in 2020, commit #4f98694bf introduced numeric priorities,
allowing [#1] to [#64] as an alternative to [#A] to [#Z]. This is also
documented in the manual.

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=4f98694bf
https://orgmode.org/manual/Priorities.html

It introduced the new function ~org-priority-to-value~, which replaces
~string-to-char~ for parsing priority strings. It parses numeric prios
as ints (1..64) and alphabetic prios as chars (?A..?Z, which is
65-90).

* PROBLEM

However, various functions within org-mode are still using
~string-to-char~ and giving inconsistent results, because numerical
priorities are parsed wrongly, or sometimes return nil (or #10 to
#64).

* EXAMPLES

With the following heading tree:

* test tree
** [#10] ten
** [#2] two

You can get the correct values 10 and 2 with: (org-priority-to-value
(thing-at-point 'line))

You can get incorrect values nil and ?2 with: (org-element-property
:priority (org-element-at-point)) or (nth 3 (org-heading-components))

And if you sort the test tree by priority (with org-sort-entries,
"p"), it won't change, because [#10] is wrongly interpreted as if it
were [#1].

* SOLUTION

If we agree that numeric priorities should be supported everywhere,
various functions need updating:

Functions that use string-to-char to parse:
- org-entry-put
- org-mobile-edit (in org-mobile.el)
- org-agenda-fontify-priorities (org-agenda.el)
- org-mouse-context-menu (org-mouse.el)

I've confirmed that org-entry-put exhibits wrong behaviour (parsing
1-9 as ?1-?9 and 10-64 as nil). I'm not familiar with the others, as
they're in modules I don't use.

The Org Element API also needs updating:
- ~org-element--headline-parse-title~ implements its own
org-priority-regexp, which doesn't account for multiple characters
- ~org-entry-put~ has bugs, but I don't understand the code well enough
- A couple of functions format priorities as "[#%c]", and should
include a %s case for values under 65.

These should all be fairly safe/uncontroversial changes to make, as
any documents that are impacted were relying on undefined behavior
(such as using chars outside of the range A-Z as priorities).

Hope that's all clear! Sorry it's a bit of an essay.


             reply	other threads:[~2024-10-13 16:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-13 16:02 Tommy Jollyboat [this message]
2024-10-13 16:11 ` [BUG] Numeric priorities only partially supported Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANDZv_N394TYMy30-KuEQV+eZ0FEkm4GSjTrkUtDViK_-DkX-Q@mail.gmail.com \
    --to=jollyboatbros@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).