unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* string-width for emojis
@ 2022-01-28 16:32 Evgeny Zajcev
  2022-01-28 19:15 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Evgeny Zajcev @ 2022-01-28 16:32 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

I'm experiencing a bin unexpected behaviour with "string-width".

If I evaluate
  (insert "ABCDEF\n"
          "\x2734\xfe0f -> "
          (format "%d" (string-width "\x2734\xfe0f")))
directly in the scratch buffer, I'll get
  ABCDEF
  ✴️ -> 2
as output.  However, if I evaluate
  (with-current-buffer (get-buffer-create "*help2*")
    (erase-buffer)
    (insert "ABCDEF\n"
            "\x2734\xfe0f -> "
            (format "%d" (string-width "\x2734\xfe0f")))
    (display-buffer (current-buffer)))
I'll get
  ABCDEF
  ✴️ -> 1
as output.

Documentation states, that "Width is measured by how many columns it
occupies on the screen."  I see visually that ✴️ occupies approximately 2
columns (see screenshot at http://lgarc.narod.ru/pics/emacs-string-width.png
)

What is the correct use of `string-width` to always get 2 as width for the
"\x2734\xfe0f" ?

Thanks

-- 
lg

[-- Attachment #2: Type: text/html, Size: 1475 bytes --]

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

* Re: string-width for emojis
  2022-01-28 16:32 string-width for emojis Evgeny Zajcev
@ 2022-01-28 19:15 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2022-01-28 19:15 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: emacs-devel

> From: Evgeny Zajcev <lg.zevlg@gmail.com>
> Date: Fri, 28 Jan 2022 19:32:47 +0300
> 
> If I evaluate
>   (insert "ABCDEF\n"
>           "\x2734\xfe0f -> "
>           (format "%d" (string-width "\x2734\xfe0f")))
> directly in the scratch buffer, I'll get
>   ABCDEF
>   ✴️ -> 2
> as output.  However, if I evaluate
>   (with-current-buffer (get-buffer-create "*help2*")
>     (erase-buffer)
>     (insert "ABCDEF\n"
>             "\x2734\xfe0f -> "
>             (format "%d" (string-width "\x2734\xfe0f")))
>     (display-buffer (current-buffer)))
> I'll get
>   ABCDEF
>   ✴️ -> 1
> as output.

I get 1 in both cases.

> Documentation states, that "Width is measured by how many columns it occupies on the screen."  I see
> visually that ✴️ occupies approximately 2 columns (see screenshot at
> http://lgarc.narod.ru/pics/emacs-string-width.png)
> 
> What is the correct use of `string-width` to always get 2 as width for the "\x2734\xfe0f" ?

The correct answer is 1, not 2, since U+2434 is a single-column
character:

  (char-width #x2734) => 1

That it takes more pixels than a single canonical character depends on
the font used to display it.  Note that the doc string warns about
inaccuracies in the returned value, and advises to use
window-text-pixel-size instead.



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

end of thread, other threads:[~2022-01-28 19:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28 16:32 string-width for emojis Evgeny Zajcev
2022-01-28 19:15 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).