all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#68441: Fix the unaligned tab in whitespace mode
@ 2024-01-13 12:23 Young Arto
  2024-01-14 10:14 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Young Arto @ 2024-01-13 12:23 UTC (permalink / raw)
  To: 68441


[-- Attachment #1.1: Type: text/plain, Size: 110 bytes --]

As described in the commit message, this patch is meant to fix the unaligned tab when tab-mark is turned on.

[-- Attachment #1.2: Type: text/html, Size: 464 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-the-unaligned-tab-with-tab-mark-of-whitespace-mo.patch --]
[-- Type: text/x-patch; name="0001-Fix-the-unaligned-tab-with-tab-mark-of-whitespace-mo.patch", Size: 2416 bytes --]

From 595ff1877c750b35077298f00ad1a9a494927ab1 Mon Sep 17 00:00:00 2001
From: Arto Young <arto.young@outlook.com>
Date: Sat, 13 Jan 2024 19:52:44 +0800
Subject: [PATCH] Fix the unaligned tab with tab-mark of whitespace mode

There is a bug in whitespace mode which used the display table to
replace a tab with a tab-mark vector.

If we has a line like this:
------
123\t5678
------

If tab-width is 4 and tab-mark is [?> ?\t],
The line will be displayed as following:
(we use '^' to represent tab extra spaces)
------
123>^^^^5678
------

However, it should be displayed as:
------
123>5678
------

If the line was:
------
12\t5678
------

It would be displayed as:
------
12>^5678
------

It happens on the boundary of tab, so we should adjust the 'next_tab_x'
in this case.

* src/term.c (produce_glyphs): Correct the next_tab_x
* src/xdisp.c (gui_produce_glyphs): Correct the next_tab_x
---
 src/term.c  | 7 +++++++
 src/xdisp.c | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/src/term.c b/src/term.c
index d3c858c6bf2..e34b2ed99de 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1642,6 +1642,13 @@ produce_glyphs (struct it *it)
 	   * it->tab_width);
       if (!NILP (Vdisplay_line_numbers) && it->line_number_produced_p)
 	next_tab_x += it->lnum_pixel_width;
+
+      /* For tab-mark display vector like [?> ?\t] for an
+	 original char '\t', we should not display ">\t"
+	 but only '>' at tab-width boundry, or tab real length
+	 will be tab-width+1, so we decrease tab-width here. */
+      if (it->c == '\t' && it->dpvec && it->current.dpvec_index > 0 && absolute_x % it->tab_width == 0)
+	next_tab_x -= it->tab_width;
       int nspaces;
 
       /* If part of the TAB has been displayed on the previous line
diff --git a/src/xdisp.c b/src/xdisp.c
index 14cf030ca4e..13fb6e5a308 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -32621,6 +32621,13 @@ gui_produce_glyphs (struct it *it)
 		    next_tab_x -= it->stretch_adjust;
 		}
 
+	      /* For tab-mark display vector like [?> ?\t] for an
+		 original char '\t', we should not display ">\t"
+		 but only '>' at tab-width boundry, or tab real length
+		 will be tab-width+1, so we decrease tab-width here. */
+	      if (it->c == '\t' && it->dpvec && it->current.dpvec_index > 0 && x % tab_width == 0)
+		next_tab_x -= tab_width;
+
 	      it->pixel_width = next_tab_x - x0;
 	      it->nglyphs = 1;
 	      if (FONT_TOO_HIGH (font))
-- 
2.43.0


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

end of thread, other threads:[~2024-01-28 11:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-13 12:23 bug#68441: Fix the unaligned tab in whitespace mode Young Arto
2024-01-14 10:14 ` Eli Zaretskii
2024-01-28 10:43   ` bug#68441: 回复: " Young Arto
2024-01-28 11:09     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.