See the patch for a full description.  Basically if you use soft
padding:
  set index_format="%-20.20s %* [ooooo]"
If the subject ends in a multi-column character and needs to be
truncated due to the soft-padding, the right hand won't always be
properly aligned.  (You may have to adjust the width of your terminal
column by column to see the effect.):

   RE: 感謝之意   [ooooo]
   Re: 生命成長冬[ooooo]
   Re: Thank you; [ooooo]

I intend to review and test the patch some more, but would appreciate if
anyone else would like to take a look too.

Thank you.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch
# User Kevin McCarthy <[email protected]>
# Date 1460429691 25200
#      Mon Apr 11 19:54:51 2016 -0700
# Node ID 2a102a2f53623474763e148bf61b826f3fee608b
# Parent  eb94f64ad81ad19f223af8e86aefe414f5ce185a
Add spacing to truncated multi-column characters when using soft-fill.

First, fix the left-hand side column truncation calculation:
  "col + pad*pw -offset"
pad = (COLS - col - wid) / pw, so this becomes
  "col + COLS - col - wid - offset" =>
  "COLS - wid - offset"

The problem is that pad was calculated *before* the right side was
mutt_wstr_trunc() truncated, which may adjust wid!  We want that
calculation, with correct values, so instead just use the final
reduction directly.  (Note, the reduction ignores integer truncation,
but pad shouldn't be used here in any case, because it's negative:
there is no padding occuring).

Second, when the left-hand side is truncated, multi-column characters
may get chopped in the middle.  Truncated characters are not included
in the wlen and col values returned.  Add spaces until the number of
columns lines up (checking to make sure we don't run out of space
too).

diff --git a/muttlib.c b/muttlib.c
--- a/muttlib.c
+++ b/muttlib.c
@@ -1309,18 +1309,26 @@
          else if (soft && pad < 0)
          {
            int offset = ((flags & M_FORMAT_ARROWCURSOR) && option 
(OPTARROWCURSOR)) ? 3 : 0;
            /* \0-terminate dest for length computation in mutt_wstr_trunc() */
            *wptr = 0;
            /* make sure right part is at most as wide as display */
            len = mutt_wstr_trunc (buf, destlen, COLS-offset, &wid);
            /* truncate left so that right part fits completely in */
-           wlen = mutt_wstr_trunc (dest, destlen - len, col + pad*pw -offset, 
&col);
+           wlen = mutt_wstr_trunc (dest, destlen - len, COLS - wid - offset, 
&col);
            wptr = dest + wlen;
+            /* Multi-column characters may be truncated in the middle.
+             * Add spacing so the right hand side lines up. */
+            while ((col + wid < COLS - offset) && (wlen + len < destlen))
+            {
+              *wptr++ = ' ';
+              col++;
+              wlen++;
+            }
          }
          if (len + wlen > destlen)
            len = mutt_wstr_trunc (buf, destlen - wlen, COLS - col, NULL);
          memcpy (wptr, buf, len);
          wptr += len;
          wlen += len;
          col += wid;
          src += pl;

Attachment: signature.asc
Description: PGP signature

Reply via email to