bug#32562: 26; `read-char(-exclusive)' and `characterp'

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#32562: 26; `read-char(-exclusive)' and `characterp'

Drew Adams
Perhaps there is no bug here, other than incomplete or insufficiently
clear doc.  Dunno.

emacs -Q
M-: (setq foo (read-char "Char: "))
M-:

shows: 134217786 (#o1000000072, #x800003a), a number too large
to be `characterp'.  And M-: (characterp foo) ; returns nil.

Same thing for `read-char-exclusive'.

Something seems wrong.  The doc for `read-char(-exclusive)' talks about
reading a character. For `read-char' it says that it raises an error for
a non-char event.  And for `read-char-exclusive' it says that it ignores
non-char events that it reads.

But they both seem to read the event from `M-:' and return its value
(a number). And it is not a character, according to `characterp'.

I'm confused.  Please consider fixing this, at least by clarifying the doc.

Why should a function that reads a character, and either ignores a
non-char or raises an error for a non-char, return a non-character?
And what function reads a `characterp' character, either ignoring
anything else or raising an error for anything else?

In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32)
 of 2018-05-30
Repository revision: 07f8f9bc5a51f5aa94eb099f3e15fbe0c20ea1ea
Windowing system distributor `Microsoft Corp.', version 10.0.16299
Configured using:
 `configure --without-dbus --host=x86_64-w64-mingw32
 --without-compress-install 'CFLAGS=-O2 -static -g3''



Reply | Threaded
Open this post in threaded view
|

bug#32562: 26; `read-char(-exclusive)' and `characterp'

Noam Postavsky
forcemerge 13599 32562
quit

On 28 August 2018 at 16:39, Drew Adams <[hidden email]> wrote:

> Something seems wrong.  The doc for `read-char(-exclusive)' talks about
> reading a character. For `read-char' it says that it raises an error for
> a non-char event.  And for `read-char-exclusive' it says that it ignores
> non-char events that it reads.
>
> But they both seem to read the event from `M-:' and return its value
> (a number). And it is not a character, according to `characterp'.

This is bug#13599/1042



Reply | Threaded
Open this post in threaded view
|

bug#32562: 26; `read-char(-exclusive)' and `characterp'

Drew Adams
> forcemerge 13599 32562
> quit
>
> > Something seems wrong.  The doc for `read-char(-exclusive)' talks about
> > reading a character. For `read-char' it says that it raises an error for
> > a non-char event.  And for `read-char-exclusive' it says that it ignores
> > non-char events that it reads.
> >
> > But they both seem to read the event from `M-:' and return its value
> > (a number). And it is not a character, according to `characterp'.
>
> This is bug#13599/1042

Hm. Maybe it is. But is `read-char' necessarily about chars that satisfy `characterp'?

I would think so, but maybe not. And there are other "character" functions, which accept chars as args - `text-char-description', for example. (That's what I was passing the result of `read-char' to.)

The doc string of `text-char-description' says "file-character CHARACTER". What's a "file character"? A character that can appear in a file name? Same thing as what `max-char' should recognize? Same thing as what `read-char' should consider a char? The Elisp manual (node Describing Characters) says it is "characters that appear in text—like ‘single-key-description’, except that..." It says nothing about "file characters". The doc is not too clear.

This stuff is not clear more generally, I think - beyond the max value of `max-char'. Do we have or want to have different kinds of "characters" returned from or passed as args to different "character" functions? Why (or why not)?

Wrt my original problem: taking a value of `M-:' from `read-char' and passing it to `text-char-description', Emacs has a regression of sorts. Older Emacs versions "work", whereas recent versions raise an error. E.g. Emacs 20 `read-char' returns -134217670, and passing that to `text-char-description' gives "\272". Whatever `read-char' can read, it seems, `text-char-description' can describe (perhaps imperfectly?).

I think that "the bug" is not so clear cut as just adjusting `max-char'. I think the behavior of several functions that expect or return chars might deserve adjustment, and the doc might deserve some clarification/fixes. We might need to decide what the right behaviors are first.



Reply | Threaded
Open this post in threaded view
|

bug#32562: 26; `read-char(-exclusive)' and `characterp'

Noam Postavsky
Drew Adams <[hidden email]> writes:

> I think that "the bug" is not so clear cut as just adjusting
> `max-char'.

No, of course not.  It's discussed at length Bug#13599.




Reply | Threaded
Open this post in threaded view
|

bug#32562: 26; `read-char(-exclusive)' and `characterp'

Eli Zaretskii
In reply to this post by Drew Adams
> Date: Tue, 28 Aug 2018 13:39:20 -0700 (PDT)
> From: Drew Adams <[hidden email]>
>
> Perhaps there is no bug here, other than incomplete or insufficiently
> clear doc.  Dunno.

It's a documentation bug.

> emacs -Q
> M-: (setq foo (read-char "Char: "))
> M-:
>
> shows: 134217786 (#o1000000072, #x800003a), a number too large
> to be `characterp'.  And M-: (characterp foo) ; returns nil.
>
> Same thing for `read-char-exclusive'.
>
> Something seems wrong.  The doc for `read-char(-exclusive)' talks about
> reading a character. For `read-char' it says that it raises an error for
> a non-char event.  And for `read-char-exclusive' it says that it ignores
> non-char events that it reads.
>
> But they both seem to read the event from `M-:' and return its value
> (a number). And it is not a character, according to `characterp'.

What the documentation failed to make clear is that the value returned
by these functions is an _event_, not a character.  For ASCII
characters, the event and the character are identical, but modifier
bits that cannot be resolved to yield an ASCII character are left in
the returned value, and that makes the value not a valid character
code.

I have now clarified this subtle point in the documentation (on the
emacs-26 branch).

> And what function reads a `characterp' character, either ignoring
> anything else or raising an error for anything else?

What do you mean by "reading a 'characterp'"?  E.g., if the user types
C-% or M-a, what 'characterp' code would you expect to see?  Also,
does "reading a 'characterp'" include supporting input methods, if
any?



Reply | Threaded
Open this post in threaded view
|

bug#32562: 26; `read-char(-exclusive)' and `characterp'

Eli Zaretskii
In reply to this post by Drew Adams
> Date: Tue, 28 Aug 2018 14:24:36 -0700 (PDT)
> From: Drew Adams <[hidden email]>
> Cc: [hidden email]
>
> is `read-char' necessarily about chars that satisfy `characterp'?

No.  It returns a character event, not a character.

> The doc string of `text-char-description' says "file-character CHARACTER". What's a "file character"? A character that can appear in a file name?

No, text-char-description accepts only valid character codes, those
which satisfy the 'characterp' test.  This is unlike
single-key-description, which accepts _events_, and thus will happily
process character input events that are not valid character codes,
i.e. fail the 'characterp' test.  I've now made that clear in the
respective doc strings.

> This stuff is not clear more generally, I think - beyond the max value of `max-char'. Do we have or want to have different kinds of "characters" returned from or passed as args to different "character" functions? Why (or why not)?

The basic difference is between a character code and a character input
event.

> Wrt my original problem: taking a value of `M-:' from `read-char' and passing it to `text-char-description', Emacs has a regression of sorts. Older Emacs versions "work", whereas recent versions raise an error. E.g. Emacs 20 `read-char' returns -134217670, and passing that to `text-char-description' gives "\272". Whatever `read-char' can read, it seems, `text-char-description' can describe (perhaps imperfectly?).

It's not a regression: text-char-description wants a valid character
code.

I'm closing this bug, as I think this is a documentation issue which
is now fixed.

Thanks.