GNU bug report logs - #64420
string-width of … is 2 in CJK environments

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dmitry <at> gutov.dev>

Date: Sun, 2 Jul 2023 12:58:02 UTC

Severity: normal

Full log


Message #26 received at 64420 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64420 <at> debbugs.gnu.org
Subject: Re: bug#64420: string-width of … is 2 in CJK environments
Date: Tue, 11 Jul 2023 05:23:03 +0300
On 02/07/2023 16:43, Eli Zaretskii wrote:
>> Since the overlay-based popup is used on both GUI and Terminal frames,
>> are you suggesting I define my own string-width like this?
>>
>> (defun company--string-width (str)
>>     (if (display-graphic-p)
>>         (ceiling (/ (string-pixel-width str)
>>                     (float (default-font-width))))
>>       (string-width str)))
> Yes, definitely.  (Actually, display-multi-font-p is better than
> display-graphic-p, but in practice they will return the same value.)

Regarding this approach, though: it seems to fail in my terminal Emacs.

Meaning, when I'm testing the feature using 'emacs -nw' (inside e.g. 
gnome-terminal), both (string-pixel-width "…") and (string-width "…") 
return 2. Whereas the character on display looks 1-character wide even 
there.

More than that, moving the cursor close to that character with C-f or 
C-b creates odd effects like the cursor jumping one position to the 
left, or a char being rendered twice at a certain position on the same 
line to the right of it (after I move the cursor there past the … char), 
in my case it's an opening paren. Nothing like that happens on the lines 
without this char, or after I switch the language env back to "English".

That happens in Emacs 29.




This bug report was last modified 2 years and 2 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.