This bug stems from the fact that iswprint(L'\t') returns false.  I
was a bit surprised that iswprint(L'\t') is considered not printable
but iswprint(L' ') is.  The man page says it is dependent on LC_CTYPE
and I tried both en_US and C and both returned 0 for a tab.

In either case, the cur_width += 8 part is incorrect.  A tab should be
expanded up to the next multiple of 8 spaces.  I think this patch
should do what is needed.

--- src/vscreen/vs_pager.cc     2005-12-09 13:23:26.000000000 -0500
+++ src/vscreen/vs_pager.cc.new 2006-02-03 22:16:17.000000000 -0500
@@ -83,13 +83,17 @@
          wchar_t ch=s[loc];
          bool printable=iswprint(ch);

-         if(ch==L'\t')
-           cur_width+=8;
-         else if(printable)
+         if(ch==L'\t') {
+           // Expand tab to next multiple of 8 spaces.
+           int tab_to_spaces = 8 - (cur_width % 8);
+           cur_width += wcwidth(L' ') * tab_to_spaces;
+           for (int i = 0; i < tab_to_spaces; i++) {
+              curline += L' ';
+           }
+         } else if(printable) {
            cur_width+=wcwidth(ch);
-
-         if(printable)
            curline+=ch;
+         }

          ++loc;
        }

Reply via email to