Subject: bug#73307: Fix ctype(3) usage

From: Paul Eggert <[email-masked]>
Date: Wed, 18 Sep 2024 08:35:18 -0700

On 2024-09-18 04:45, Eli Zaretskii wrote:
> what's the
> problem with using c_isspace (and what do you mean by "multibyte
> space"

Using c_isspace would be OK, in that it'd handle most practical 
examples. I wrote the fancier version to handle prompts that end in 
non-ASCII spaces, e.g., (yes-or-no-p "Delete all files? ") where the 
last character is actually U+00A0 NO-BREAK_SPACE instead of U+0020 
SPACE, so its UTF-8 encoding is multiple bytes. If it's not important to 
handle such cases we could just use c_isspace.

> You are testing characters for whitespace syntax, which is AFAIU
> subject to buffer-local syntax tables.

Thanks, I didn't think of that. How about the attached patch? It is an 
alternative to just using c_isspace.

diff --git a/src/fns.c b/src/fns.c
index 370f7711b90..d3ee98c3bae 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -35,7 +35,6 @@ 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"
@@ -3579,8 +3578,7 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0,
   ptrdiff_t promptlen = SCHARS (prompt);
   bool prompt_ends_in_nonspace
     = (0 < promptlen
-       && (SYNTAX (XFIXNAT (Faref (prompt, make_fixnum (promptlen - 1))))
-	   != Swhitespace));
+       && !blankp (XFIXNAT (Faref (prompt, make_fixnum (promptlen - 1)))));
   AUTO_STRING (space_string, " ");
   prompt = CALLN (Fconcat, prompt,
 		  prompt_ends_in_nonspace ? space_string : empty_unibyte_string,