* Bug in sorting headings according to priority
@ 2023-12-17 0:22 Zelphir Kaltstahl
2023-12-17 14:04 ` Ihor Radchenko
0 siblings, 1 reply; 2+ messages in thread
From: Zelphir Kaltstahl @ 2023-12-17 0:22 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3138 bytes --]
Hello Org-mode users!
I have observed a mini bug over some time now:
When I sort headings in org mode according to their priority (C-c ^ p),
sometimes the last heading (lowest priority) will not get its own line, but will
be put in one line with the second last heading, making it no longer a separate
heading, but part of the second last actual heading.
This behavior depends on how one marks/selects/highlights the headings to be
sorted. If one highlights the headings from top to bottom, moving the point to
the next line after the last heading that shall be sorted, then it works without
merging the last heading and the second last. However, if one does not move the
point to the next line, then the described behavior occurs.
I have the suspicion, that this is about each heading being defined as
consisting also of a final newline character and since one does not select that
as well by moving the point past it, org mode does not consider the last heading
to be a separate heading, but instead thinks it is part of the second last
heading. Or perhaps, that it only considers selected text to be sorted, not
headings that continue after selected text and therefore forgets to include a
newline for the last heading and if that heading moves around without the
newline, another heading will be joined on to it on the same line, if any
heading comes afterwards in the sorted result.
When one highlights from bottom to top (so the other way around!) the same thing
happens. If one started highlighting on the line below the last heading, then
the sorting works without merging the last two lines. However, if one starts
highlighting on the last heading line, then again org mode puts the last heading
on the line of the second last heading.
Of course this is quite annoying, when one sorts a lot, and one has to always be
careful how one selects the headings.
Note also, that this only happens, when org mode sorting actually would change
the order of headings. If the headings are already sorted, then this does not
happen.
Here is an example document:
~~~~
* 1
** [#A] 2.1
** [#C] 2.2
** [#B] 2.3
~~~~
In this document move the cursor:
~~~~
* 1
** [#A] 2.1
** [#C] 2.2
** [#B] 2.3
^
`--- cursor here
~~~~
Then select until the start of the first level 2 heading, so that all level 2
headings are selected.
Then run `org-sort' or press `C-c ^' and then `p'.
The result is:
~~~~
* 1
** [#A] 2.1
** [#B] 2.3** [#C] 2.2
~~~~
Instead of:
~~~~
* 1
** [#A] 2.1
** [#B] 2.3
** [#C] 2.2
~~~~
This also happens, when I try it in an Emacs started with `emacs -Q'.
In my opinions org-sort should sort without merging headings. It should probably
consider all text until the end of even a partially selected/highlighted heading
including the final newline character to avoid this.
* Emacs version: GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.37, cairo version 1.16.0)
* org-mode version: 9.6.7
Please let me know, in case more details are required and how to get them.
Best regards,
Zelphir
--
repositories:https://notabug.org/ZelphirKaltstahl
[-- Attachment #2: Type: text/html, Size: 3948 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Bug in sorting headings according to priority
2023-12-17 0:22 Bug in sorting headings according to priority Zelphir Kaltstahl
@ 2023-12-17 14:04 ` Ihor Radchenko
0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2023-12-17 14:04 UTC (permalink / raw)
To: Zelphir Kaltstahl; +Cc: emacs-orgmode
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> writes:
> Here is an example document:
>
> ~~~~
> * 1
> ** [#A] 2.1
> ** [#C] 2.2
> ** [#B] 2.3
> ~~~~
> ...
> The result is:
>
> ~~~~
> * 1
> ** [#A] 2.1
> ** [#B] 2.3** [#C] 2.2
> ~~~~
Thanks for reporting!
Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=67ce9386a
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=92fec81e2
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-17 14:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-17 0:22 Bug in sorting headings according to priority Zelphir Kaltstahl
2023-12-17 14:04 ` Ihor Radchenko
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).