From 55a9298d63121578cd66ef7f14c14b2160aae77d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 24 Jun 2017 14:29:32 +0300 Subject: Fix tab stops when line numbers are displayed * src/xdisp.c (x_produce_glyphs): * src/term.c (produce_glyphs): Adjust tab stops for the horizontal space taken by the line-number display. --- src/term.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/term.c') diff --git a/src/term.c b/src/term.c index 8770aff8a92..b0e7e052e51 100644 --- a/src/term.c +++ b/src/term.c @@ -1584,6 +1584,10 @@ produce_glyphs (struct it *it) { int absolute_x = (it->current_x + it->continuation_lines_width); + /* Adjust for line numbers. Kludge alert: the "2" below is + because we add 2 blanks to the actual line number. */ + if (!NILP (Vdisplay_line_numbers)) + absolute_x -= it->lnum_width + 2; int next_tab_x = (((1 + absolute_x + it->tab_width - 1) / it->tab_width) -- cgit v1.3 From 13cc19a0a3685ceade4a5a560475ee47165f3bbc Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 24 Jun 2017 19:03:39 +0300 Subject: Partial fix of hscroll of truncated lines with line numbers * src/xdisp.c (x_produce_glyphs, hscroll_window_tree): Adjust hscroll calculations to line-number display. * src/term.c (produce_glyphs): Adjust tab stop to window's hscroll. These two changes fix horizontal scrolling when line numbers are displayed. But there's still a bug: the horizontal shift of lines that begin with a TAB is different from the rest. * src/xdisp.c (move_it_in_display_line_to): Call should_produce_line_number to determine whether a line number should be produced for this screen line. --- src/term.c | 2 +- src/xdisp.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'src/term.c') diff --git a/src/term.c b/src/term.c index b0e7e052e51..46d8bff73cc 100644 --- a/src/term.c +++ b/src/term.c @@ -1587,7 +1587,7 @@ produce_glyphs (struct it *it) /* Adjust for line numbers. Kludge alert: the "2" below is because we add 2 blanks to the actual line number. */ if (!NILP (Vdisplay_line_numbers)) - absolute_x -= it->lnum_width + 2; + absolute_x -= it->lnum_width + 2 - it->w->hscroll; int next_tab_x = (((1 + absolute_x + it->tab_width - 1) / it->tab_width) diff --git a/src/xdisp.c b/src/xdisp.c index d35170ed43e..d0673595390 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -834,6 +834,7 @@ static bool update_menu_bar (struct frame *, bool, bool); static bool try_window_reusing_current_matrix (struct window *); static int try_window_id (struct window *); static void maybe_produce_line_number (struct it *); +static bool should_produce_line_number (struct it *); static bool display_line (struct it *, int); static int display_mode_lines (struct window *); static int display_mode_line (struct window *, enum face_id, Lisp_Object); @@ -8656,7 +8657,7 @@ move_it_in_display_line_to (struct it *it, if (it->hpos == 0) { /* If line numbers are being displayed, produce a line number. */ - if (!NILP (Vdisplay_line_numbers) + if (should_produce_line_number (it) && it->current_x == it->first_visible_x) maybe_produce_line_number (it); /* If there's a line-/wrap-prefix, handle it. */ @@ -13068,6 +13069,30 @@ hscroll_window_tree (Lisp_Object window) } bool row_r2l_p = cursor_row->reversed_p; bool hscl = hscrolling_current_line_p (w); + int x_offset = 0; + struct glyph *g; + if (!row_r2l_p) + { + for (g = cursor_row->glyphs[TEXT_AREA]; + g < cursor_row->glyphs[TEXT_AREA] + cursor_row->used[TEXT_AREA]; + g++) + { + if (!(NILP (g->object) && g->charpos < 0)) + break; + x_offset += g->pixel_width; + } + } + else + { + for (g = cursor_row->glyphs[TEXT_AREA] + cursor_row->used[TEXT_AREA]; + g > cursor_row->glyphs[TEXT_AREA]; + g--) + { + if (!(NILP ((g - 1)->object) && (g - 1)->charpos < 0)) + break; + x_offset += (g - 1)->pixel_width; + } + } text_area_width = window_box_width (w, TEXT_AREA); @@ -13100,7 +13125,7 @@ hscroll_window_tree (Lisp_Object window) inside the left margin and the window is already hscrolled. */ && ((!row_r2l_p - && ((w->hscroll && w->cursor.x <= h_margin) + && ((w->hscroll && w->cursor.x <= h_margin + x_offset) || (cursor_row->enabled_p && cursor_row->truncated_on_right_p && (w->cursor.x >= text_area_width - h_margin)))) @@ -13118,7 +13143,8 @@ hscroll_window_tree (Lisp_Object window) && cursor_row->truncated_on_right_p && w->cursor.x <= h_margin) || (w->hscroll - && (w->cursor.x >= text_area_width - h_margin)))) + && (w->cursor.x >= (text_area_width - h_margin + - x_offset))))) /* This last condition is needed when moving vertically from an hscrolled line to a short line that doesn't need to be hscrolled. If we omit @@ -27898,7 +27924,7 @@ x_produce_glyphs (struct it *it) /* Adjust for line numbers. Kludge alert: the "2" below is because we add 2 blanks to the actual line number. */ if (!NILP (Vdisplay_line_numbers)) - x -= (it->lnum_width + 2) * font->space_width; + x -= (it->lnum_width + 2 - it->w->hscroll) * font->space_width; int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; /* If the distance from the current position to the next tab -- cgit v1.3 From a06dd3b9187489b61f08256d9e9a07745302dc4e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 30 Jun 2017 12:24:13 +0300 Subject: Fix hscrolling with line numbers on TTY frames * src/xdisp.c (hscroll_window_tree): Correct the X offset calculations on TTY frames. * src/term.c (produce_glyphs): Use it->lnum_pixel_width instead of a kludge using it->lnum_width. --- src/term.c | 10 ++++++---- src/xdisp.c | 9 ++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/term.c') diff --git a/src/term.c b/src/term.c index 46d8bff73cc..00a272c3b0b 100644 --- a/src/term.c +++ b/src/term.c @@ -1584,14 +1584,16 @@ produce_glyphs (struct it *it) { int absolute_x = (it->current_x + it->continuation_lines_width); - /* Adjust for line numbers. Kludge alert: the "2" below is - because we add 2 blanks to the actual line number. */ + int x0 = absolute_x; + /* Adjust for line numbers. */ if (!NILP (Vdisplay_line_numbers)) - absolute_x -= it->lnum_width + 2 - it->w->hscroll; + absolute_x -= it->lnum_pixel_width; int next_tab_x = (((1 + absolute_x + it->tab_width - 1) / it->tab_width) * it->tab_width); + if (!NILP (Vdisplay_line_numbers)) + next_tab_x += it->lnum_pixel_width; int nspaces; /* If part of the TAB has been displayed on the previous line @@ -1599,7 +1601,7 @@ produce_glyphs (struct it *it) been incremented already by the part that fitted on the continued line. So, we will get the right number of spaces here. */ - nspaces = next_tab_x - absolute_x; + nspaces = next_tab_x - x0; if (it->glyph_row) { diff --git a/src/xdisp.c b/src/xdisp.c index 3fc5f29d0c4..26b19eb44fb 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -13100,6 +13100,12 @@ hscroll_window_tree (Lisp_Object window) } } } + if (cursor_row->truncated_on_left_p) + { + /* On TTY frames, don't count the left truncation glyph. */ + struct frame *f = XFRAME (WINDOW_FRAME (w)); + x_offset -= (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)); + } text_area_width = window_box_width (w, TEXT_AREA); @@ -28004,7 +28010,8 @@ x_produce_glyphs (struct it *it) x -= it->lnum_pixel_width; int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; if (!NILP (Vdisplay_line_numbers)) - next_tab_x += it->lnum_pixel_width; + next_tab_x += (it->lnum_pixel_width + - it->w->hscroll * font->space_width); /* If the distance from the current position to the next tab stop is less than a space character width, use the -- cgit v1.3