unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Mikhail Efremov <jakutenshi@gmail.com>
Cc: 71323@debbugs.gnu.org
Subject: bug#71323: 28.2; global-display-line-numbers-mode in org file do strange identation when headers are folded
Date: Sun, 02 Jun 2024 15:20:41 +0300	[thread overview]
Message-ID: <86le3nmt7q.fsf@gnu.org> (raw)
In-Reply-To: <994aaad088f1e26429986a95996a02e7b9d4a1a3.camel@gmail.com> (message from Mikhail Efremov on Sun, 02 Jun 2024 15:10:46 +0600)

tags 71323 notabug
thanks

> From: Mikhail Efremov <jakutenshi@gmail.com>
> Date: Sun, 02 Jun 2024 15:10:46 +0600
> 
> * Description
> 
> There is an issue with not so large org files with
> global-display-line-numbers-mode is toggled on. You may reproduce it:
> 
> 1. ~emacs -Q~
> 2. open an org file with 1000+ lines of different headers' layers
> unfolded.
> 3. ~M-x global-display-line-numbers-mode~
> 4. Check that unfolded headers on lines 999-1000 are indented fine:
>   - numbers are right-aligned;
>   - same-level headers are indented equally with the same indent width
>   relative to line numbers.
> 5. Fold all headers with the property: on the screen of the buffer
> there
> are single-, two- and three-digits lines' numbers are presented.
> 
> Then, you should see the picture like this:
> 
>   1 * header1
>  24 * header2
> 132 * header3
> 1019 * header4
> 
> The same behavior is on ~emacs -nw -Q~.
> 
> The issue is valid also on built from sources emacs: GNU Emacs 29.3
> (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version
> 1.16.0) of 2024-04-08
> 
> * Motivation
> 
> This behavior on the one hand constantly shifts
> left-to-right-and-vice-versa the buffer's text and also confuses with
> headers' identation level.
> 
> * Definition of Done
> 
> After the steps of reproducing the desired view is:
>    1 * header1
>   24 * header2
>  132 * header3
> 1019 * header4

You should be able to have this if you customize
display-line-numbers-width-start to a non-nil value.  Consider also
customizing display-line-numbers-grow-only to a non-nil value.

> * Details of implementation
> 
> I guess there is a problem with line's mode algorithm, from my side
> it looks like it taking into account only 1 digit difference for an
> identation, then if there is 2 or more digits differnece, then all
> after the first-digit diff identations are broken.

No, that's not what happens.  The problem is that the required width
of the line-number display needs to be calculated when the window is
about to be shown on display or redisplayed due to scrolling etc.  At
that time, the display-engine code which does this calculation cannot
know up front how many lines are hidden by 'invisible' text properties
and overlays, something that Org uses a lot, and therefore cannot
correctly estimate the largest line number to be shown.  So its
estimation of the maximum number of the line in the window are
incorrect in those cases.

Customizing display-line-numbers-width-start fixes that problem, for a
price of a slightly slower initial display of the window.  It could
still fail if you add a lot of lines to the buffer, in which case
toggling display-line-numbers-mode off and on again should fix it.

> The posible solution is to count total lines number and reserving
> line's numbers side width from total lines count number's width.

That's exactly what the above user option does, when non-nil.

There's no bug here.





  reply	other threads:[~2024-06-02 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-02  9:10 bug#71323: 28.2; global-display-line-numbers-mode in org file do strange identation when headers are folded Mikhail Efremov
2024-06-02 12:20 ` Eli Zaretskii [this message]
     [not found]   ` <588dc873eff0f9fc9ecbd78766288ed213b3089a.camel@gmail.com>
2024-06-04 14:49     ` Eli Zaretskii
2024-06-30  6:10       ` Stefan Kangas

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=86le3nmt7q.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=71323@debbugs.gnu.org \
    --cc=jakutenshi@gmail.com \
    /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.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).