From 43cde03fa5a663a1509a762077c11eb57a60cee8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 17 Sep 2024 15:22:02 -0700 Subject: [PATCH 1/4] Fix yes-or-no-p with multibyte spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/fns.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/fns.c b/src/fns.c index 57113a8c5ed..370f7711b90 100644 --- a/src/fns.c +++ b/src/fns.c @@ -26,7 +26,6 @@ Copyright (C) 1985-2024 Free Software Foundation, Inc. #include #include #include -#include #include #include "lisp.h" @@ -36,6 +35,7 @@ Copyright (C) 1985-2024 Free Software Foundation, Inc. #include "composite.h" #include "buffer.h" #include "intervals.h" +#include "syntax.h" #include "window.h" #include "puresize.h" #include "gnutls.h" @@ -3576,13 +3576,15 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0, 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 (); specbind (Qenable_recursive_minibuffers, Qt); -- 2.43.0