bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#60094: current-column returns an incorrect number of columns for som


From: Eli Zaretskii
Subject: bug#60094: current-column returns an incorrect number of columns for some characters
Date: Thu, 15 Dec 2022 18:56:43 +0200

tags 60094 notabug
thanks

> From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
> Date: Thu, 15 Dec 2022 11:40:55 -0500
> 
> In the minimal working example below, you can see that `current-columns'
> returns `2' when the line contains an emoji and the cursor is located
> after it.
> 
> ,----
> | cat ~/e/main.el
> `----
> 
> ,----
> | (with-temp-buffer
> |   (insert "👋")
> |   (end-of-line)
> |   (princ (current-column)))
> `----
> 
> ,----
> | emacs -Q --batch -l ~/e/main.el
> `----
> 
> ,----
> | 2
> `----
> 
> In the minimal working example below, you can see that `current-columns'
> returns `2' when the line contains a Chinese character and the cursor is
> located after it.
> 
> ,----
> | cat ~/e/main.el
> `----
> 
> ,----
> | (with-temp-buffer
> |   (insert "ä½ ")
> |   (end-of-line)
> |   (princ (current-column)))
> `----
> 
> ,----
> | emacs -Q --batch -l ~/e/main.el
> `----
> 
> ,----
> | 2
> `----

These are the expected and correct results: these characters have
width that is very close to 2 canonical columns.  And current-column
counts canonical columns, not just characters.

If you type regular characters, like 'a', above or below this Emoji or
the Chinese character, you will see that for each such Emoji you can
type 2 regular characters.

So there's no bug here: Emacs does what it's supposed to do.  The doc
string of current-column says:

  This is calculated by adding together the widths of all the displayed
  representations of the character between the start of the previous line
  and point (e.g., control characters will have a width of 2 or 4, tabs
  will have a variable width).

Note the "displayed representations" part.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]