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.
This commit is contained in:
Paul Eggert 2024-09-17 15:22:02 -07:00
parent f1794a17b6
commit 43cde03fa5

View file

@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <intprops.h>
#include <vla.h>
#include <errno.h>
#include <ctype.h>
#include <math.h>
#include "lisp.h"
@ -36,6 +35,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#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 @@ 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 ();
specbind (Qenable_recursive_minibuffers, Qt);