From: Paul Eggert Date: Tue, 17 Sep 2024 22:22:02 +0000 (-0700) Subject: Fix yes-or-no-p with multibyte spaces X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=90c84c728e5200e521b5c02a3c40763bd80ef4a3;p=emacs.git Fix yes-or-no-p with multibyte spaces Problem reported by Thomas Klausner (Bug#73307). Emacs shouldn’t use ctype.h, as it doesn’t work for multibyte chars and it doesn’t work with Emacs’s locale model anyway. * src/fns.c: Include syntax.h, not ctype.h. (Fyes_or_no_p): Check the character category with SYNTAX, not with isspace, which assumes the current locale and works only with single-byte characters. (cherry picked from commit 43cde03fa5a663a1509a762077c11eb57a60cee8) --- diff --git a/src/fns.c b/src/fns.c index 5881f147fd8..be9faa3af06 100644 --- a/src/fns.c +++ b/src/fns.c @@ -26,7 +26,6 @@ along with GNU Emacs. If not, see . */ #include #include #include -#include #include #include "lisp.h" @@ -36,6 +35,7 @@ along with GNU Emacs. If not, see . */ #include "composite.h" #include "buffer.h" #include "intervals.h" +#include "syntax.h" #include "window.h" #include "puresize.h" #include "gnutls.h" @@ -3574,13 +3574,15 @@ by a mouse, or by some window-system gesture, or via a menu. */) if (use_short_answers) return call1 (Qy_or_n_p, prompt); - { - char *s = SSDATA (prompt); - ptrdiff_t len = strlen (s); - if ((len > 0) && !isspace (s[len - 1])) - prompt = CALLN (Fconcat, prompt, build_string (" ")); - } - prompt = CALLN (Fconcat, prompt, Vyes_or_no_prompt); + ptrdiff_t promptlen = SCHARS (prompt); + bool prompt_ends_in_nonspace + = (0 < promptlen + && (SYNTAX (XFIXNAT (Faref (prompt, make_fixnum (promptlen - 1)))) + != Swhitespace)); + AUTO_STRING (space_string, " "); + prompt = CALLN (Fconcat, prompt, + prompt_ends_in_nonspace ? space_string : empty_unibyte_string, + Vyes_or_no_prompt); specpdl_ref count = SPECPDL_INDEX (); /* Preserve the actual command that eventually called `yes-or-no-p'