emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 7f2b98d: Curved quotes in --batch diagnostics in no


From: Paul Eggert
Subject: [Emacs-diffs] master 7f2b98d: Curved quotes in --batch diagnostics in non-UTF-8
Date: Mon, 17 Aug 2015 19:01:30 +0000

branch: master
commit 7f2b98d09d113e0f9b1fffb0524622adfafe3ac4
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Curved quotes in --batch diagnostics in non-UTF-8
    
    When run with --batch, check that curved quotes are compatible with
    the system locale before outputting them in diagnostics.
    Problem reported by Eli Zaretskii in:
    http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00594.html
    * lisp/startup.el (command-line): Set internal--text-quoting-flag
    after the standard display table is initialized.
    * src/doc.c (default_to_grave_quoting_style): New function.
    (text_quoting_style): Use it.
    (text_quoting_flag): New static var, visible to Lisp as
    internal--text-quoting-flag.
    * src/emacs.c: Include <wchar.h> if available.
    (using_utf8): New function.
    (main): Use it to initialize text_quoting_flag.
    * src/regex.h (btowc) [WIDE_CHAR_SUPPORT && emacs]:
    Don't define, as it's not needed and it clashes with wchar.h.
---
 lisp/startup.el |    1 +
 src/doc.c       |   33 ++++++++++++++++++++++-----------
 src/emacs.c     |   18 ++++++++++++++++++
 src/regex.h     |    4 +++-
 4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 3248a99..ec159c2 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1023,6 +1023,7 @@ please check its value")
       (or standard-display-table
           (setq standard-display-table (make-display-table)))
       (aset standard-display-table (car char-repl) (cdr char-repl))))
+  (setq internal--text-quoting-flag t)
 
   ;; Re-evaluate predefined variables whose initial value depends on
   ;; the runtime context.
diff --git a/src/doc.c b/src/doc.c
index 977953d..9c9bdf3 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -688,24 +688,31 @@ the same file name is found in the `doc-directory'.  */)
 static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 };
 static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 };
 
+static bool
+default_to_grave_quoting_style (void)
+{
+  if (!text_quoting_flag)
+    return true;
+  if (! DISP_TABLE_P (Vstandard_display_table))
+    return false;
+  Lisp_Object dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table),
+                                    LEFT_SINGLE_QUOTATION_MARK);
+  return (VECTORP (dv) && ASIZE (dv) == 1
+         && EQ (AREF (dv, 0), make_number ('`')));
+}
+
 /* Return the current effective text quoting style.  */
 enum text_quoting_style
 text_quoting_style (void)
 {
-  if (EQ (Vtext_quoting_style, Qgrave))
+  if (NILP (Vtext_quoting_style)
+      ? default_to_grave_quoting_style ()
+      : EQ (Vtext_quoting_style, Qgrave))
     return GRAVE_QUOTING_STYLE;
   else if (EQ (Vtext_quoting_style, Qstraight))
     return STRAIGHT_QUOTING_STYLE;
-  else if (NILP (Vtext_quoting_style)
-          && DISP_TABLE_P (Vstandard_display_table))
-    {
-      Lisp_Object dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table),
-                                        LEFT_SINGLE_QUOTATION_MARK);
-      if (VECTORP (dv) && ASIZE (dv) == 1
-         && EQ (AREF (dv, 0), make_number ('`')))
-       return GRAVE_QUOTING_STYLE;
-    }
-  return CURVE_QUOTING_STYLE;
+  else
+    return CURVE_QUOTING_STYLE;
 }
 
 DEFUN ("substitute-command-keys", Fsubstitute_command_keys,
@@ -1045,6 +1052,10 @@ The default value nil acts like ‘curve’ if curved single 
quotes are
 displayable, and like ‘grave’ otherwise.  */);
   Vtext_quoting_style = Qnil;
 
+  DEFVAR_BOOL ("internal--text-quoting-flag", text_quoting_flag,
+              doc: /* If nil, a nil ‘text-quoting-style’ is treated as 
‘grave’.  */);
+  /* Initialized by ‘main’.  */
+
   defsubr (&Sdocumentation);
   defsubr (&Sdocumentation_property);
   defsubr (&Ssnarf_documentation);
diff --git a/src/emacs.c b/src/emacs.c
index 80bb70c..1392209 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -95,6 +95,10 @@ extern void moncontrol (int mode);
 #include <locale.h>
 #endif
 
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
 #ifdef HAVE_SETRLIMIT
 #include <sys/time.h>
 #include <sys/resource.h>
@@ -344,6 +348,19 @@ setlocale (int cat, char const *locale)
 }
 #endif
 
+/* True if the current system locale uses UTF-8 encoding.  */
+static bool
+using_utf8 (void)
+{
+#ifdef HAVE_WCHAR_H
+  wchar_t wc;
+  mbstate_t mbs = { 0 };
+  return mbrtowc (&wc, "\xc4\x80", 2, &mbs) == 2 && wc == 0x100;
+#else
+  return false;
+#endif
+}
+
 
 /* Report a fatal error due to signal SIG, output a backtrace of at
    most BACKTRACE_LIMIT lines, and exit.  */
@@ -924,6 +941,7 @@ main (int argc, char **argv)
      fixup_locale must wait until later, since it builds strings.  */
   if (do_initial_setlocale)
     setlocale (LC_ALL, "");
+  text_quoting_flag = using_utf8 ();
 
   inhibit_window_system = 0;
 
diff --git a/src/regex.h b/src/regex.h
index 3dfecf0..c89ca46 100644
--- a/src/regex.h
+++ b/src/regex.h
@@ -603,7 +603,9 @@ typedef wchar_t re_wchar_t;
 # define re_wctype_to_bit(cc) 0
 #else
 # define CHAR_CLASS_MAX_LENGTH  9 /* Namely, `multibyte'.  */
-# define btowc(c) c
+# ifndef emacs
+#  define btowc(c) c
+# endif
 
 /* Character classes.  */
 typedef enum { RECC_ERROR = 0,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]