emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 582222b: Fix quoting in ‘message_with_string’


From: Paul Eggert
Subject: [Emacs-diffs] master 582222b: Fix quoting in ‘message_with_string’
Date: Wed, 26 Aug 2015 20:12:30 +0000

branch: master
commit 582222b557b271d3dc2f27138c39c3ae5d915030
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Fix quoting in ‘message_with_string’
    
    * src/nsfont.m (nsfont_open): Use directed quotes in format; they
    should work now.
    * src/xdisp.c (message_to_stderr): New function, refactored from
    part of ‘message3_nolog’.
    (message3_nolog): Use it.
    (message_with_string): Use it.  Don’t mishandle NUL bytes when
    noninteractive.  Prefer AUTO_STRING when it’s most likely faster.
    Use ‘format-message’, not ‘format’, so that quotes are translated.
---
 src/nsfont.m |    2 +-
 src/xdisp.c  |   81 ++++++++++++++++++++++++++++-----------------------------
 2 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/src/nsfont.m b/src/nsfont.m
index d450df3..3d278c0 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -781,7 +781,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int 
pixel_size)
 
   if (nsfont == nil)
     {
-      message_with_string ("*** Warning: font in family '%s' not found",
+      message_with_string ("*** Warning: font in family `%s' not found",
                           build_string ([family UTF8String]), 1);
       nsfont = [NSFont userFixedPitchFontOfSize: pixel_size];
     }
diff --git a/src/xdisp.c b/src/xdisp.c
index f752936..08802de 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10124,6 +10124,25 @@ message3 (Lisp_Object m)
   UNGCPRO;
 }
 
+/* Log the message M to stderr.  Log an empty line if M is not a string.  */
+
+static void
+message_to_stderr (Lisp_Object m)
+{
+  if (noninteractive_need_newline)
+    {
+      noninteractive_need_newline = false;
+      fputc ('\n', stderr);
+    }
+  if (STRINGP (m))
+    {
+      Lisp_Object s = ENCODE_SYSTEM (m);
+      fwrite (SDATA (s), SBYTES (s), 1, stderr);
+    }
+  if (!cursor_in_echo_area)
+    fputc ('\n', stderr);
+  fflush (stderr);
+}
 
 /* The non-logging version of message3.
    This does not cancel echoing, because it is used for echoing.
@@ -10136,20 +10155,7 @@ message3_nolog (Lisp_Object m)
   struct frame *sf = SELECTED_FRAME ();
 
   if (FRAME_INITIAL_P (sf))
-    {
-      if (noninteractive_need_newline)
-       putc ('\n', stderr);
-      noninteractive_need_newline = false;
-      if (STRINGP (m))
-       {
-         Lisp_Object s = ENCODE_SYSTEM (m);
-
-         fwrite (SDATA (s), SBYTES (s), 1, stderr);
-       }
-      if (!cursor_in_echo_area)
-       fprintf (stderr, "\n");
-      fflush (stderr);
-    }
+    message_to_stderr (m);
   /* Error messages get reported properly by cmd_error, so this must be just an
      informative message; if the frame hasn't really been initialized yet, just
      toss it.  */
@@ -10216,24 +10222,12 @@ message_with_string (const char *m, Lisp_Object 
string, bool log)
 {
   CHECK_STRING (string);
 
+  bool need_message;
   if (noninteractive)
-    {
-      if (m)
-       {
-         /* ENCODE_SYSTEM below can GC and/or relocate the
-            Lisp data, so make sure we don't use it here.  */
-         eassert (relocatable_string_data_p (m) != 1);
-
-         if (noninteractive_need_newline)
-           putc ('\n', stderr);
-         noninteractive_need_newline = false;
-         fprintf (stderr, m, SDATA (ENCODE_SYSTEM (string)));
-         if (!cursor_in_echo_area)
-           fprintf (stderr, "\n");
-         fflush (stderr);
-       }
-    }
-  else if (INTERACTIVE)
+    need_message = !!m;
+  else if (!INTERACTIVE)
+    need_message = false;
+  else
     {
       /* The frame whose minibuffer we're going to display the message on.
         It may be larger than the selected frame, so we need
@@ -10249,27 +10243,32 @@ message_with_string (const char *m, Lisp_Object 
string, bool log)
       /* Error messages get reported properly by cmd_error, so this must be
         just an informative message; if the frame hasn't really been
         initialized yet, just toss it.  */
-      if (f->glyphs_initialized_p)
-       {
-         struct gcpro gcpro1, gcpro2;
-
-         Lisp_Object fmt = build_string (m);
-         Lisp_Object msg = string;
-         GCPRO2 (fmt, msg);
+      need_message = f->glyphs_initialized_p;
+    }
 
-         msg = CALLN (Fformat, fmt, msg);
+  if (need_message)
+    {
+      AUTO_STRING (fmt, m);
+      struct gcpro gcpro1;
+      Lisp_Object msg = string;
+      GCPRO1 (msg);
+      msg = CALLN (Fformat_message, fmt, msg);
 
+      if (noninteractive)
+       message_to_stderr (msg);
+      else
+       {
          if (log)
            message3 (msg);
          else
            message3_nolog (msg);
 
-         UNGCPRO;
-
          /* Print should start at the beginning of the message
             buffer next time.  */
          message_buf_print = false;
        }
+
+      UNGCPRO;
     }
 }
 



reply via email to

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