Subject: Re: bug#64420: string-width of … is 2 in CJK environments

From: Yuan Fu <[email-masked]>
Date: Sat, 12 Aug 2023 13:18:03 -0700

> On Aug 11, 2023, at 11:36 AM, Eli Zaretskii <[email-masked]> wrote:
> 
>> From: Yuan Fu <[email-masked]>
>> Date: Fri, 11 Aug 2023 11:07:26 -0700
>> Cc: [email-masked],
>> [email-masked],
>> [email-masked]
>> 
>> On terminal, I saw an interesting option, “Ambiguous characters are double-width” (terminal-setting.png), which is the same as cjk-ambiguous-chars-are-wide. If I turn it on all the ambiguous characters are indeed displayed in double-width. (terminal-narrow.png, terminal-wide.png)
> 
> And in that case, you need to set cjk-ambiguous-chars-are-wide non-nil
> to have Emacs display those characters correctly?  Or does that option
> have no effect on the correctness of the |Emacs display on that
> terminal?

The value of cjk-ambiguous-chars-are-wide has no effect on the display of those characters in the terminal, at least in the terminal I use (iTerm2). Only the terminal option has an effect.

The screenshot I took are actually from cat, not Emacs. I tried with Emacs and found out that the terminal and Emacs must agree on the width of those characters, otherwise the cursor movement is broken (perhaps that’s not surprising to you). The cursor movement works if either a) I turn on "Ambiguous characters are double-width” in the terminal and (set-language-environment "Chinese-BIG5”) in Emacs, or b) I turn off "Ambiguous characters are double-width” (which is off by default) and use default locale (utf8_enUS).

> 
>> On GUI display, the later-half of the ambiguous characters are definitely wider than one char, but they aren’t quite 2 chars wide either. But I guess it doesn’t matter too much since one should use pixel size on GUI anyway.
> 
> Is the actual width closer to 1 or to 2?
> 

I’d say 2.

Yuan