Mercurial > emacs
comparison src/print.c @ 16512:59835b743b93
(PRINTDECLARE): Declare specpdl_count and free_print_buffer.
(PRINTPREPARE): If print_buffer is nonzero,
save its contents in a string using record_unwind_protect.
(PRINTFINISH): Restore old print_buffer contents.
Free it only if this PRINTPREPARE malloc'd it.
(print): Don't call PRINTFULLP after all.
(print_unwind): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 04 Nov 1996 05:31:25 +0000 |
parents | a4e5a8ee32cc |
children | ecf0700e9550 |
comparison
equal
deleted
inserted
replaced
16511:f81633edcbf5 | 16512:59835b743b93 |
---|---|
167 */ | 167 */ |
168 | 168 |
169 #define PRINTDECLARE \ | 169 #define PRINTDECLARE \ |
170 struct buffer *old = current_buffer; \ | 170 struct buffer *old = current_buffer; \ |
171 int old_point = -1, start_point; \ | 171 int old_point = -1, start_point; \ |
172 int specpdl_count = specpdl_ptr - specpdl; \ | |
173 int free_print_buffer = 0; \ | |
172 Lisp_Object original | 174 Lisp_Object original |
173 | 175 |
174 #define PRINTPREPARE \ | 176 #define PRINTPREPARE \ |
175 original = printcharfun; \ | 177 original = printcharfun; \ |
176 if (NILP (printcharfun)) printcharfun = Qt; \ | 178 if (NILP (printcharfun)) printcharfun = Qt; \ |
177 if (BUFFERP (printcharfun)) \ | 179 if (BUFFERP (printcharfun)) \ |
178 { if (XBUFFER (printcharfun) != current_buffer) \ | 180 { \ |
181 if (XBUFFER (printcharfun) != current_buffer) \ | |
179 Fset_buffer (printcharfun); \ | 182 Fset_buffer (printcharfun); \ |
180 printcharfun = Qnil;} \ | 183 printcharfun = Qnil; \ |
184 } \ | |
181 if (MARKERP (printcharfun)) \ | 185 if (MARKERP (printcharfun)) \ |
182 { if (!(XMARKER (original)->buffer)) \ | 186 { \ |
187 if (!(XMARKER (original)->buffer)) \ | |
183 error ("Marker does not point anywhere"); \ | 188 error ("Marker does not point anywhere"); \ |
184 if (XMARKER (original)->buffer != current_buffer) \ | 189 if (XMARKER (original)->buffer != current_buffer) \ |
185 set_buffer_internal (XMARKER (original)->buffer); \ | 190 set_buffer_internal (XMARKER (original)->buffer); \ |
186 old_point = PT; \ | 191 old_point = PT; \ |
187 SET_PT (marker_position (printcharfun)); \ | 192 SET_PT (marker_position (printcharfun)); \ |
188 start_point = PT; \ | 193 start_point = PT; \ |
189 printcharfun = Qnil;} \ | 194 printcharfun = Qnil; \ |
195 } \ | |
190 if (NILP (printcharfun)) \ | 196 if (NILP (printcharfun)) \ |
191 { \ | 197 { \ |
198 if (print_buffer != 0) \ | |
199 record_unwind_protect (print_unwind, \ | |
200 make_string (print_buffer, \ | |
201 print_buffer_pos)); \ | |
202 else \ | |
203 { \ | |
204 print_buffer_size = 1000; \ | |
205 print_buffer = (char *) xmalloc (print_buffer_size); \ | |
206 free_print_buffer = 0; \ | |
207 } \ | |
192 print_buffer_pos = 0; \ | 208 print_buffer_pos = 0; \ |
193 print_buffer_size = 1000; \ | |
194 print_buffer = (char *) xmalloc (print_buffer_size); \ | |
195 } \ | 209 } \ |
196 else \ | |
197 print_buffer = 0; \ | |
198 printed_gensyms = Qnil | 210 printed_gensyms = Qnil |
199 | 211 |
200 #define PRINTFINISH \ | 212 #define PRINTFINISH \ |
201 if (NILP (printcharfun)) \ | 213 if (NILP (printcharfun)) \ |
202 insert (print_buffer, print_buffer_pos); \ | 214 insert (print_buffer, print_buffer_pos); \ |
203 if (print_buffer) \ | 215 if (free_print_buffer) \ |
204 { \ | 216 { \ |
205 free (print_buffer); \ | 217 free (print_buffer); \ |
206 print_buffer = 0; \ | 218 print_buffer = 0; \ |
207 } \ | 219 } \ |
220 unbind_to (specpdl_count, Qnil); \ | |
208 if (MARKERP (original)) \ | 221 if (MARKERP (original)) \ |
209 Fset_marker (original, make_number (PT), Qnil); \ | 222 Fset_marker (original, make_number (PT), Qnil); \ |
210 if (old_point >= 0) \ | 223 if (old_point >= 0) \ |
211 SET_PT (old_point + (old_point >= start_point \ | 224 SET_PT (old_point + (old_point >= start_point \ |
212 ? PT - start_point : 0)); \ | 225 ? PT - start_point : 0)); \ |
220 so print might as well return right away. */ | 233 so print might as well return right away. */ |
221 | 234 |
222 #define PRINTFULLP() \ | 235 #define PRINTFULLP() \ |
223 (EQ (printcharfun, Qt) && !noninteractive \ | 236 (EQ (printcharfun, Qt) && !noninteractive \ |
224 && printbufidx >= FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window))))) | 237 && printbufidx >= FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window))))) |
238 | |
239 /* This is used to restore the saved contents of print_buffer | |
240 when there is a recursive call to print. */ | |
241 static Lisp_Object | |
242 print_unwind (saved_text) | |
243 Lisp_Object saved_text; | |
244 { | |
245 bcopy (XSTRING (saved_text)->data, print_buffer, XSTRING (saved_text)->size); | |
246 } | |
225 | 247 |
226 /* Index of first unused element of FRAME_MESSAGE_BUF (mini_frame). */ | 248 /* Index of first unused element of FRAME_MESSAGE_BUF (mini_frame). */ |
227 static int printbufidx; | 249 static int printbufidx; |
228 | 250 |
229 static void | 251 static void |
854 int escapeflag; | 876 int escapeflag; |
855 { | 877 { |
856 char buf[30]; | 878 char buf[30]; |
857 | 879 |
858 QUIT; | 880 QUIT; |
859 if (PRINTFULLP ()) | |
860 return; | |
861 | 881 |
862 #if 1 /* I'm not sure this is really worth doing. */ | 882 #if 1 /* I'm not sure this is really worth doing. */ |
863 /* Detect circularities and truncate them. | 883 /* Detect circularities and truncate them. |
864 No need to offer any alternative--this is better than an error. */ | 884 No need to offer any alternative--this is better than an error. */ |
865 if (CONSP (obj) || VECTORP (obj) || COMPILEDP (obj)) | 885 if (CONSP (obj) || VECTORP (obj) || COMPILEDP (obj)) |