unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: monnier@iro.umontreal.ca, 64696@debbugs.gnu.org
Subject: bug#64696: 30.0.50; indent-to inherits preceding text properties, including 'invisible
Date: Sat, 22 Jul 2023 14:22:47 +0300	[thread overview]
Message-ID: <83wmys8a2g.fsf@gnu.org> (raw)
In-Reply-To: <87zg3o8m2a.fsf@localhost> (message from Ihor Radchenko on Sat, 22 Jul 2023 07:03:41 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: monnier@iro.umontreal.ca, 64696@debbugs.gnu.org
> Date: Sat, 22 Jul 2023 07:03:41 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> You can do M-x yant/full-test after evaluating the code below
> >
> > And what are the problems you see with current-column in this example?
> > (Let's leave indent-to alone for now.)
> 
> ⛔ Warning (emacs): Test #1:: Everything visible.
> ⛔ Warning (emacs): Moved point after first ’word’
> ⛔ Warning (emacs): 1:: current-column = 4
> 
> Test #1 is expected - everything is visible, we are indeed at column 4.
> 
> ⛔ Warning (emacs): Test #2:: ’word’ is inside folded heading (hidden using overlays).
> ⛔ Warning (emacs): Moved point after first ’word’
> ⛔ Warning (emacs): 1:: current-column = 4
> 
> Test #2 is unexpected - we are inside invisible region, but
> current-column reports as if everything were visible.

current-column produces incorrect results when the newline before the
current line is invisible.  It always starts from the beginning of the
current physical line, even if that is in invisible text.

We could teach current-column about invisible newlines, see the patch
below.  But I'm not sure this is justified, nor whether it won't break
something.  The patch below also has a disadvantage that it will still
behave as before for a buffer that is not displayed in any window; if
we want that to be fixed as well, the changes will need to be more
extensive.  (Basically, we will need to write a non-display version of
back_to_previous_visible_line_start.)

With the patch below, Test #2 shows "current-column = 6", which is
correct, since the cursor is shown after "* Test", with all the rest
invisible.

If we think this kind of change is a good idea (Stefan?), patches to
make the below work without employing display code (which needs the
window) will be welcome.

diff --git a/src/indent.c b/src/indent.c
index eda85f2..1357fd2 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -563,11 +563,35 @@ scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol,
   ptrdiff_t end = endpos ? *endpos : PT;
   ptrdiff_t scan, scan_byte, next_boundary, prev_pos, prev_bpos;
 
-  scan = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &scan_byte, 1);
-
   window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
   w = ! NILP (window) ? XWINDOW (window) : NULL;
 
+  int prevbyte = 0;
+  Lisp_Object prop = Qnil;
+  if (PT > BEGV && w)
+    {
+      prevbyte = FETCH_BYTE (PT_BYTE - 1);
+      prop  = Fget_char_property (make_fixnum (PT - 1), Qinvisible, window);
+    }
+  if (w && !(prevbyte == '\n' && TEXT_PROP_MEANS_INVISIBLE (prop) == 0))
+    {
+      struct it it;
+      struct text_pos pt;
+      specpdl_ref count = SPECPDL_INDEX ();
+      void *itdata = bidi_shelve_cache ();
+      SET_TEXT_POS (pt, PT, PT_BYTE);
+      record_unwind_protect_void (unwind_display_working_on_window);
+      display_working_on_window_p = true;
+      start_display (&it, w, pt);
+      reseat_at_previous_visible_line_start (&it);
+      scan = IT_CHARPOS (it);
+      scan_byte = IT_BYTEPOS (it);
+      bidi_unshelve_cache (itdata, 0);
+      unbind_to (count, Qnil);
+    }
+  else
+    scan = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &scan_byte, 1);
+
   if (current_buffer->long_line_optimizations_p)
     {
       bool lines_truncated = false;





  reply	other threads:[~2023-07-22 11:22 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18  7:58 bug#64696: 30.0.50; indent-to inherits preceding text properties, including 'invisible Ihor Radchenko
2023-07-18 11:23 ` Eli Zaretskii
2023-07-18 12:09   ` Ihor Radchenko
2023-07-18 13:10     ` Eli Zaretskii
2023-07-18 13:25       ` Ihor Radchenko
2023-07-18 16:13         ` Eli Zaretskii
2023-07-18 16:25           ` Ihor Radchenko
2023-07-18 17:08             ` Eli Zaretskii
2023-07-19  8:30               ` Ihor Radchenko
2023-07-19 13:07                 ` Eli Zaretskii
2023-07-20  9:10                   ` Ihor Radchenko
2023-07-21  8:32                     ` Ihor Radchenko
2023-07-22  6:51                       ` Eli Zaretskii
2023-07-22  7:09                         ` Ihor Radchenko
2023-07-22 11:35                           ` Eli Zaretskii
2023-07-22 14:10                             ` Ihor Radchenko
2023-07-22 14:31                               ` Eli Zaretskii
2023-07-22  6:49                     ` Eli Zaretskii
2023-07-22  7:03                       ` Ihor Radchenko
2023-07-22 11:22                         ` Eli Zaretskii [this message]
2023-07-22 14:05                           ` Ihor Radchenko
2023-07-22 14:28                             ` Eli Zaretskii
2023-07-23  7:30                               ` Ihor Radchenko
2023-07-23 10:05                                 ` Eli Zaretskii
2023-07-24  8:18                                   ` Ihor Radchenko
2023-07-24 13:09                                     ` Eli Zaretskii
2023-07-25  8:38                                       ` Ihor Radchenko
2023-07-25 12:37                                         ` Eli Zaretskii
2023-07-27  8:58                                           ` Ihor Radchenko
2023-07-27  9:15                                             ` Eli Zaretskii
2023-07-28  8:06                                               ` Ihor Radchenko
2023-07-28 11:52                                                 ` Eli Zaretskii
2023-07-29  9:00                                                   ` Ihor Radchenko
2023-07-29 10:33                                                     ` Eli Zaretskii
2023-07-30  7:51                                                       ` Ihor Radchenko
2023-07-30  9:59                                                         ` Eli Zaretskii
2023-07-30 11:45                                                           ` Ihor Radchenko
2023-07-30 17:11                                                             ` Eli Zaretskii
2023-07-31  7:18                                                               ` Ihor Radchenko
2023-07-31 11:49                                                                 ` Eli Zaretskii
2023-07-28  2:53                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-28  8:30                                       ` Ihor Radchenko
2023-07-28 12:06                                         ` Eli Zaretskii
2023-07-28 12:26                                           ` Ihor Radchenko
2023-07-28 12:48                                             ` Eli Zaretskii
2023-07-28 13:02                                               ` Ihor Radchenko
2023-07-28 14:17                                                 ` Eli Zaretskii
2023-07-29  9:06                                                   ` Ihor Radchenko
2023-07-22 13:32                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-18 14:15     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-18 16:20       ` Eli Zaretskii
2023-07-18 19:33         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-19  8:42           ` Ihor Radchenko
2023-07-19 13:10             ` Eli Zaretskii
2023-07-19 14:25               ` Ihor Radchenko
2023-07-19 15:09                 ` Eli Zaretskii
2023-07-19  8:41       ` Ihor Radchenko
2023-07-19 13:51         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=83wmys8a2g.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=64696@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=yantar92@posteo.net \
    /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).