unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
@ 2023-01-09 17:34 Juri Linkov
  2023-01-09 18:34 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2023-01-09 17:34 UTC (permalink / raw)
  To: 60692

When there is an outline ellipsis displayed at the end of outline headings,
then the correct indentation 2 is returned in this test case:

(progn
  (switch-to-buffer (get-buffer-create "test1"))
  (insert "* h\n  .\n")
  (outline-mode)
  (outline-hide-sublevels 1)
  (goto-char 8)
  (current-indentation))

But when the ellipsis is disabled with invisibility-spec:

(progn
  (switch-to-buffer (get-buffer-create "test2"))
  (insert "* h\n  .\n")
  (outline-mode)
  (remove-from-invisibility-spec '(outline . t))
  (add-to-invisibility-spec 'outline)
  (outline-hide-sublevels 1)
  (goto-char 8)
  (current-indentation))

then the returned indentation is 0 that is incorrect.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
  2023-01-09 17:34 bug#60692: 29.0.60; current-indentation wrong without outline ellipsis Juri Linkov
@ 2023-01-09 18:34 ` Eli Zaretskii
  2023-01-09 19:10   ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-01-09 18:34 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60692

> From: Juri Linkov <juri@linkov.net>
> Date: Mon, 09 Jan 2023 19:34:07 +0200
> 
> When there is an outline ellipsis displayed at the end of outline headings,
> then the correct indentation 2 is returned in this test case:
> 
> (progn
>   (switch-to-buffer (get-buffer-create "test1"))
>   (insert "* h\n  .\n")
>   (outline-mode)
>   (outline-hide-sublevels 1)
>   (goto-char 8)
>   (current-indentation))

How is 2 correct in this case?  I'd expect 6.  2 is correct when point
is on 'h'.

> But when the ellipsis is disabled with invisibility-spec:
> 
> (progn
>   (switch-to-buffer (get-buffer-create "test2"))
>   (insert "* h\n  .\n")
>   (outline-mode)
>   (remove-from-invisibility-spec '(outline . t))
>   (add-to-invisibility-spec 'outline)
>   (outline-hide-sublevels 1)
>   (goto-char 8)
>   (current-indentation))
> 
> then the returned indentation is 0 that is incorrect.

I think they are both incorrect, because the algorithm in
current-indentation doesn't expect that the current line is entirely
made of invisible text.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
  2023-01-09 18:34 ` Eli Zaretskii
@ 2023-01-09 19:10   ` Eli Zaretskii
  2023-01-10  8:20     ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-01-09 19:10 UTC (permalink / raw)
  To: juri; +Cc: 60692

> Cc: 60692@debbugs.gnu.org
> Date: Mon, 09 Jan 2023 20:34:50 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > From: Juri Linkov <juri@linkov.net>
> > Date: Mon, 09 Jan 2023 19:34:07 +0200
> > 
> > When there is an outline ellipsis displayed at the end of outline headings,
> > then the correct indentation 2 is returned in this test case:
> > 
> > (progn
> >   (switch-to-buffer (get-buffer-create "test1"))
> >   (insert "* h\n  .\n")
> >   (outline-mode)
> >   (outline-hide-sublevels 1)
> >   (goto-char 8)
> >   (current-indentation))
> 
> How is 2 correct in this case?  I'd expect 6.  2 is correct when point
> is on 'h'.

Sorry, I was confused.  I thought we were talking about
current-column.

About current-indentation: it skips invisible text, so it's unclear to
me why you expected to see 2.  The doc string says:

  Text that has an invisible property is considered as having width 0, unless
  `buffer-invisibility-spec' specifies that it is replaced by an ellipsis.

The "current indentation" on the line of buffer position 8 is entirely
in invisible text, and current-indentation only accounts for _visible_
whitespace, per the above documentation.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
  2023-01-09 19:10   ` Eli Zaretskii
@ 2023-01-10  8:20     ` Juri Linkov
  2023-01-10 13:29       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2023-01-10  8:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 60692

forcemerge 56837 60692
thanks

> About current-indentation: it skips invisible text, so it's unclear to
> me why you expected to see 2.  The doc string says:
>
>   Text that has an invisible property is considered as having width 0, unless
>   `buffer-invisibility-spec' specifies that it is replaced by an ellipsis.
>
> The "current indentation" on the line of buffer position 8 is entirely
> in invisible text, and current-indentation only accounts for _visible_
> whitespace, per the above documentation.

Thanks for the reference, it explains the problem.
But this is a very strange logic.  I don't get it.
Why it depends on the presence of the ellipsis
and fails without it?

Now I see this bug report is a duplicate of bug#56837.
This is a problem because modes use 'current-indentation'
to get an outline level in 'outline-level' function, e.g.

  (setq-local outline-level
              (lambda ()
                "`outline-level' function for Python mode."
                (1+ (/ (current-indentation) python-indent-offset))))

  (setq-local outline-level (lambda () (1+ (/ (current-indentation)
                                         ruby-indent-level))))

But this fails when users want to remove an ellipsis.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
  2023-01-10  8:20     ` Juri Linkov
@ 2023-01-10 13:29       ` Eli Zaretskii
  2023-01-10 17:54         ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-01-10 13:29 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60692

> From: Juri Linkov <juri@linkov.net>
> Cc: 60692@debbugs.gnu.org
> Date: Tue, 10 Jan 2023 10:20:20 +0200
> 
> forcemerge 56837 60692
> thanks
> 
> > About current-indentation: it skips invisible text, so it's unclear to
> > me why you expected to see 2.  The doc string says:
> >
> >   Text that has an invisible property is considered as having width 0, unless
> >   `buffer-invisibility-spec' specifies that it is replaced by an ellipsis.
> >
> > The "current indentation" on the line of buffer position 8 is entirely
> > in invisible text, and current-indentation only accounts for _visible_
> > whitespace, per the above documentation.
> 
> Thanks for the reference, it explains the problem.
> But this is a very strange logic.  I don't get it.
> Why it depends on the presence of the ellipsis
> and fails without it?
> 
> Now I see this bug report is a duplicate of bug#56837.

If you've read the discussion of bug#56837, then I explained there why
this is how it is.  In a nutshell, indentation is regarded as
display-related aspect, so asking about indentation of invisible text
makes no sense.

I added that note to the doc string because Ihor asked for that, not
in order to describe some algorithmic logic.

> This is a problem because modes use 'current-indentation'
> to get an outline level in 'outline-level' function, e.g.
> 
>   (setq-local outline-level
>               (lambda ()
>                 "`outline-level' function for Python mode."
>                 (1+ (/ (current-indentation) python-indent-offset))))
> 
>   (setq-local outline-level (lambda () (1+ (/ (current-indentation)
>                                          ruby-indent-level))))
> 
> But this fails when users want to remove an ellipsis.

I'm surprised the indentation is used for this purpose when it is
known that text will be sometimes hidden.  May I suggest to use text
properties for this purpose?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
  2023-01-10 13:29       ` Eli Zaretskii
@ 2023-01-10 17:54         ` Juri Linkov
  2023-01-10 18:13           ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2023-01-10 17:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 60692

> If you've read the discussion of bug#56837, then I explained there why
> this is how it is.  In a nutshell, indentation is regarded as
> display-related aspect, so asking about indentation of invisible text
> makes no sense.

But when an ellipsis is used, current-indentation
works correctly in invisible text.

>>   (setq-local outline-level
>>               (lambda ()
>>                 "`outline-level' function for Python mode."
>>                 (1+ (/ (current-indentation) python-indent-offset))))
>>
>>   (setq-local outline-level (lambda () (1+ (/ (current-indentation)
>>                                          ruby-indent-level))))
>>
>> But this fails when users want to remove an ellipsis.
>
> I'm surprised the indentation is used for this purpose when it is
> known that text will be sometimes hidden.  May I suggest to use text
> properties for this purpose?

I don't understand how text properties could be used to get
the indentation.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#60692: 29.0.60; current-indentation wrong without outline ellipsis
  2023-01-10 17:54         ` Juri Linkov
@ 2023-01-10 18:13           ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2023-01-10 18:13 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60692

> From: Juri Linkov <juri@linkov.net>
> Cc: 60692@debbugs.gnu.org
> Date: Tue, 10 Jan 2023 19:54:11 +0200
> 
> > If you've read the discussion of bug#56837, then I explained there why
> > this is how it is.  In a nutshell, indentation is regarded as
> > display-related aspect, so asking about indentation of invisible text
> > makes no sense.
> 
> But when an ellipsis is used, current-indentation
> works correctly in invisible text.

Because the ellipsis replaces the invisible text, and
current-indentation accounts for the ellipsis.  When the ellipsis
isn't present, there's nothing to account for.

In any case, if you want to know the indentation disregarding
invisible property, current-indentation is not what you want.

> 
> >>   (setq-local outline-level
> >>               (lambda ()
> >>                 "`outline-level' function for Python mode."
> >>                 (1+ (/ (current-indentation) python-indent-offset))))
> >>
> >>   (setq-local outline-level (lambda () (1+ (/ (current-indentation)
> >>                                          ruby-indent-level))))
> >>
> >> But this fails when users want to remove an ellipsis.
> >
> > I'm surprised the indentation is used for this purpose when it is
> > known that text will be sometimes hidden.  May I suggest to use text
> > properties for this purpose?
> 
> I don't understand how text properties could be used to get
> the indentation.

Before you hide anything, analyze the indentation and assign to each
outline level the value of the property that equals the level.  Then
you can know the level of any piece of text just by accessing the
property value.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-10 18:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 17:34 bug#60692: 29.0.60; current-indentation wrong without outline ellipsis Juri Linkov
2023-01-09 18:34 ` Eli Zaretskii
2023-01-09 19:10   ` Eli Zaretskii
2023-01-10  8:20     ` Juri Linkov
2023-01-10 13:29       ` Eli Zaretskii
2023-01-10 17:54         ` Juri Linkov
2023-01-10 18:13           ` Eli Zaretskii

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).