Subject: Re: bug#29002: it.first_visible_x is erroneously 0 while horizontal scrolling.

From: Keith David Bershatsky <[email-masked]>
Date: Sun, 29 Oct 2017 10:29:29 -0700

Here is a link to screen-shot #3:

https://www.lawlist.com/images/bug_hscl_03.png

In that screen-shot, we make the following observations:

* A total of 5 screen lines.

* Line 1 is the current line.

* All 5 lines visually appear to be horizontally scrolled.

* Using the revised function bug-hscroll (below), we iterate over each screen line and generate the values for it.first_visible_x and it.vpos.

* it.first_visible_x returns as being 0 for each of the 5 screen lines.

It is as though Emacs is unaware that the non-current lines still visually appear to be hscrolled, because Emacs "thinks" they are not.

DEFUN ("bug-hscroll", Fbug_hscroll, Sbug_hscroll, 0, 0, 0,
       doc: /* Demonstrate the Emacs hscroll bug. */)
  (void)
{
  struct window *w = decode_live_window (selected_window);
  struct it it;
  void *itdata = bidi_shelve_cache ();
  struct text_pos start_text_position;
  Lisp_Object temp = Qnil;
  Lisp_Object result = Qnil;
  Vmax_mini_window_height = make_number (1);
  SET_TEXT_POS_FROM_MARKER (start_text_position, w->start);
  start_display (&it, w, start_text_position);
  while (true)
    {
      temp = listn (CONSTYPE_HEAP, 3,
                    make_number (it.vpos),
                    build_string (" | "),
                    make_number (it.first_visible_x));
      result = Fcons (temp, result);
      if (IT_CHARPOS (it) == ZV)
        break;
      move_it_by_lines (&it, 1);
      if (it.current_y >= it.last_visible_y)
        break;
    }
  bidi_unshelve_cache (itdata, false);
  result = Fnreverse (result);
  AUTO_STRING (my_string_one, "%s");
  CALLN (Fmessage, my_string_one, result);
  return result;
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [10-29-2017 04:23:07] <29 Oct 2017 13:23:07 +0200>
FROM:  Eli Zaretskii <[email-masked]>
> 
> > Date:  Thu, 26 Oct 2017 11:56:08 -0700
> > From:  Keith David Bershatsky <[email-masked]>
> > Cc:  [email-masked]
> > 
> > Unfortunately, w->min_hscroll returns a value of 0 in this example.
> 
> For the lines other than the current one, you should use
> it.first_visible_x, it is simpler.  For the current line, use
> w->hscroll.