emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: emacs-orgmode@gnu.org
Subject: Bug in sorting headings according to priority
Date: Sun, 17 Dec 2023 00:22:21 +0000	[thread overview]
Message-ID: <8d637a8a-6cbc-4158-bded-f9182716a1fc@posteo.de> (raw)

[-- 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 --]

             reply	other threads:[~2023-12-17  0:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-17  0:22 Zelphir Kaltstahl [this message]
2023-12-17 14:04 ` Bug in sorting headings according to priority 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=8d637a8a-6cbc-4158-bded-f9182716a1fc@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --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).