aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-08-26 13:11:57 -0700
committerPaul Eggert2015-08-26 13:12:26 -0700
commit582222b557b271d3dc2f27138c39c3ae5d915030 (patch)
treebf251f3f3d54a5b1db98b698d4e7b5788490aa43 /src
parent84a978724217516694620bbc4ab6fb02075c137c (diff)
downloademacs-582222b557b271d3dc2f27138c39c3ae5d915030.tar.gz
emacs-582222b557b271d3dc2f27138c39c3ae5d915030.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/nsfont.m2
-rw-r--r--src/xdisp.c81
2 files changed, 41 insertions, 42 deletions
diff --git a/src/nsfont.m b/src/nsfont.m
index d450df3c13e..3d278c0f2fb 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)
781 781
782 if (nsfont == nil) 782 if (nsfont == nil)
783 { 783 {
784 message_with_string ("*** Warning: font in family '%s' not found", 784 message_with_string ("*** Warning: font in family `%s' not found",
785 build_string ([family UTF8String]), 1); 785 build_string ([family UTF8String]), 1);
786 nsfont = [NSFont userFixedPitchFontOfSize: pixel_size]; 786 nsfont = [NSFont userFixedPitchFontOfSize: pixel_size];
787 } 787 }
diff --git a/src/xdisp.c b/src/xdisp.c
index f75293618e8..08802de2f9b 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10124,6 +10124,25 @@ message3 (Lisp_Object m)
10124 UNGCPRO; 10124 UNGCPRO;
10125} 10125}
10126 10126
10127/* Log the message M to stderr. Log an empty line if M is not a string. */
10128
10129static void
10130message_to_stderr (Lisp_Object m)
10131{
10132 if (noninteractive_need_newline)
10133 {
10134 noninteractive_need_newline = false;
10135 fputc ('\n', stderr);
10136 }
10137 if (STRINGP (m))
10138 {
10139 Lisp_Object s = ENCODE_SYSTEM (m);
10140 fwrite (SDATA (s), SBYTES (s), 1, stderr);
10141 }
10142 if (!cursor_in_echo_area)
10143 fputc ('\n', stderr);
10144 fflush (stderr);
10145}
10127 10146
10128/* The non-logging version of message3. 10147/* The non-logging version of message3.
10129 This does not cancel echoing, because it is used for echoing. 10148 This does not cancel echoing, because it is used for echoing.
@@ -10136,20 +10155,7 @@ message3_nolog (Lisp_Object m)
10136 struct frame *sf = SELECTED_FRAME (); 10155 struct frame *sf = SELECTED_FRAME ();
10137 10156
10138 if (FRAME_INITIAL_P (sf)) 10157 if (FRAME_INITIAL_P (sf))
10139 { 10158 message_to_stderr (m);
10140 if (noninteractive_need_newline)
10141 putc ('\n', stderr);
10142 noninteractive_need_newline = false;
10143 if (STRINGP (m))
10144 {
10145 Lisp_Object s = ENCODE_SYSTEM (m);
10146
10147 fwrite (SDATA (s), SBYTES (s), 1, stderr);
10148 }
10149 if (!cursor_in_echo_area)
10150 fprintf (stderr, "\n");
10151 fflush (stderr);
10152 }
10153 /* Error messages get reported properly by cmd_error, so this must be just an 10159 /* Error messages get reported properly by cmd_error, so this must be just an
10154 informative message; if the frame hasn't really been initialized yet, just 10160 informative message; if the frame hasn't really been initialized yet, just
10155 toss it. */ 10161 toss it. */
@@ -10216,24 +10222,12 @@ message_with_string (const char *m, Lisp_Object string, bool log)
10216{ 10222{
10217 CHECK_STRING (string); 10223 CHECK_STRING (string);
10218 10224
10225 bool need_message;
10219 if (noninteractive) 10226 if (noninteractive)
10220 { 10227 need_message = !!m;
10221 if (m) 10228 else if (!INTERACTIVE)
10222 { 10229 need_message = false;
10223 /* ENCODE_SYSTEM below can GC and/or relocate the 10230 else
10224 Lisp data, so make sure we don't use it here. */
10225 eassert (relocatable_string_data_p (m) != 1);
10226
10227 if (noninteractive_need_newline)
10228 putc ('\n', stderr);
10229 noninteractive_need_newline = false;
10230 fprintf (stderr, m, SDATA (ENCODE_SYSTEM (string)));
10231 if (!cursor_in_echo_area)
10232 fprintf (stderr, "\n");
10233 fflush (stderr);
10234 }
10235 }
10236 else if (INTERACTIVE)
10237 { 10231 {
10238 /* The frame whose minibuffer we're going to display the message on. 10232 /* The frame whose minibuffer we're going to display the message on.
10239 It may be larger than the selected frame, so we need 10233 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)
10249 /* Error messages get reported properly by cmd_error, so this must be 10243 /* Error messages get reported properly by cmd_error, so this must be
10250 just an informative message; if the frame hasn't really been 10244 just an informative message; if the frame hasn't really been
10251 initialized yet, just toss it. */ 10245 initialized yet, just toss it. */
10252 if (f->glyphs_initialized_p) 10246 need_message = f->glyphs_initialized_p;
10253 { 10247 }
10254 struct gcpro gcpro1, gcpro2;
10255
10256 Lisp_Object fmt = build_string (m);
10257 Lisp_Object msg = string;
10258 GCPRO2 (fmt, msg);
10259 10248
10260 msg = CALLN (Fformat, fmt, msg); 10249 if (need_message)
10250 {
10251 AUTO_STRING (fmt, m);
10252 struct gcpro gcpro1;
10253 Lisp_Object msg = string;
10254 GCPRO1 (msg);
10255 msg = CALLN (Fformat_message, fmt, msg);
10261 10256
10257 if (noninteractive)
10258 message_to_stderr (msg);
10259 else
10260 {
10262 if (log) 10261 if (log)
10263 message3 (msg); 10262 message3 (msg);
10264 else 10263 else
10265 message3_nolog (msg); 10264 message3_nolog (msg);
10266 10265
10267 UNGCPRO;
10268
10269 /* Print should start at the beginning of the message 10266 /* Print should start at the beginning of the message
10270 buffer next time. */ 10267 buffer next time. */
10271 message_buf_print = false; 10268 message_buf_print = false;
10272 } 10269 }
10270
10271 UNGCPRO;
10273 } 10272 }
10274} 10273}
10275 10274