unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60094: current-column returns an incorrect number of columns for some characters
@ 2022-12-15 16:40 Rodrigo Morales
  2022-12-15 16:56 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Morales @ 2022-12-15 16:40 UTC (permalink / raw)
  To: 60094

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

TL; DR: `current-column' returns `2' when the cursor is in the first
column and the line contains a single emoji or a Chinese character. The
expected value is `1' as happens when the line contains `a' or even the
highest defined codepoint in Unicode: `U+10FFFD'.

In the minimal working example below, you can see that `current-columns'
returns `1' when the line contains the character `a' and the cursor is
located after it.

,----
| cat ~/e/main.el
`----

,----
| (with-temp-buffer
|   (insert "a")
|   (end-of-line)
|   (princ (current-column)))
`----

,----
| emacs -Q --batch -l ~/e/main.el
`----

,----
| 1
`----

In the minimal working example below, you can see that `current-columns'
returns `1' when the line contains the character `􏿽' (highest defined
codepoint in Unicode, U+10FFFD) 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
`----

,----
| 1
`----

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
`----

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

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

* bug#60094: current-column returns an incorrect number of columns for some characters
  2022-12-15 16:40 bug#60094: current-column returns an incorrect number of columns for some characters Rodrigo Morales
@ 2022-12-15 16:56 ` Eli Zaretskii
  2023-09-04 21:11   ` Stefan Kangas
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2022-12-15 16:56 UTC (permalink / raw)
  To: Rodrigo Morales; +Cc: 60094

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.





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

* bug#60094: current-column returns an incorrect number of columns for some characters
  2022-12-15 16:56 ` Eli Zaretskii
@ 2023-09-04 21:11   ` Stefan Kangas
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Kangas @ 2023-09-04 21:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 60094-done, Rodrigo Morales

Eli Zaretskii <eliz@gnu.org> writes:

> tags 60094 notabug
> thanks
[...]
> 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.

Thanks, I'm therefore closing this bug report.





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

end of thread, other threads:[~2023-09-04 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15 16:40 bug#60094: current-column returns an incorrect number of columns for some characters Rodrigo Morales
2022-12-15 16:56 ` Eli Zaretskii
2023-09-04 21:11   ` Stefan Kangas

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).