aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Naggum1996-09-08 23:19:05 +0000
committerErik Naggum1996-09-08 23:19:05 +0000
commit081e0581b6c36a417d9d1de2fee438c110e4a859 (patch)
tree5e9b3e3db616c821ba7ed992f7faefeba164cfaf /src
parent79bdae7a236f6ec3423282da13e20b1ecc25bf04 (diff)
downloademacs-081e0581b6c36a417d9d1de2fee438c110e4a859.tar.gz
emacs-081e0581b6c36a417d9d1de2fee438c110e4a859.zip
Add #n=object, #n#, and #:symbol constructs to printer.
(PRINTDECLARE): New macro to declare required variables. (PRINTPREPARE, PRINTFINISH): Set printed_genyms to nil. (Fwrite_char, write_string, write_string_1, Fterpri, Fprin1, Fprin1_to_string, Fprinc, Fprint): Use new macro PRINTDECLARE. (print): Print uninterned symbols readable. (syms_of_print): Defvar `print-gensym', staticpro printed_gensyms.
Diffstat (limited to 'src')
-rw-r--r--src/print.c117
1 files changed, 72 insertions, 45 deletions
diff --git a/src/print.c b/src/print.c
index d6b850b9c48..bb4725a5ae7 100644
--- a/src/print.c
+++ b/src/print.c
@@ -82,7 +82,15 @@ Lisp_Object Qprint_escape_newlines;
82 82
83int print_quoted; 83int print_quoted;
84 84
85Lisp_Object Qprint_quoted; 85/* Nonzero means print #: before uninterned symbols. */
86
87int print_gensym;
88
89/* Association list of certain objects that are `eq' in the form being
90 printed and which should be `eq' when read back in, using the #n=object
91 and #n# reader forms. Each element has the form (object . n). */
92
93Lisp_Object printed_gensyms;
86 94
87/* Nonzero means print newline to stdout before next minibuffer message. 95/* Nonzero means print newline to stdout before next minibuffer message.
88 Defined in xdisp.c */ 96 Defined in xdisp.c */
@@ -151,16 +159,18 @@ glyph_to_str_cpy (glyphs, str)
151/* Low level output routines for characters and strings */ 159/* Low level output routines for characters and strings */
152 160
153/* Lisp functions to do output using a stream 161/* Lisp functions to do output using a stream
154 must have the stream in a variable called printcharfun 162 must have the stream in a variable called printcharfun
155 and must start with PRINTPREPARE and end with PRINTFINISH. 163 and must start with PRINTPREPARE, end with PRINTFINISH,
156 Use PRINTCHAR to output one character, 164 and use PRINTDECLARE to declare common variables.
157 or call strout to output a block of characters. 165 Use PRINTCHAR to output one character,
158 Also, each one must have the declarations 166 or call strout to output a block of characters.
159 struct buffer *old = current_buffer;
160 int old_point = -1, start_point;
161 Lisp_Object original;
162*/ 167*/
163 168
169#define PRINTDECLARE \
170 struct buffer *old = current_buffer; \
171 int old_point = -1, start_point; \
172 Lisp_Object original
173
164#define PRINTPREPARE \ 174#define PRINTPREPARE \
165 original = printcharfun; \ 175 original = printcharfun; \
166 if (NILP (printcharfun)) printcharfun = Qt; \ 176 if (NILP (printcharfun)) printcharfun = Qt; \
@@ -184,7 +194,8 @@ glyph_to_str_cpy (glyphs, str)
184 print_buffer = (char *) xmalloc (print_buffer_size); \ 194 print_buffer = (char *) xmalloc (print_buffer_size); \
185 } \ 195 } \
186 else \ 196 else \
187 print_buffer = 0; 197 print_buffer = 0; \
198 printed_gensyms = Qnil
188 199
189#define PRINTFINISH \ 200#define PRINTFINISH \
190 if (NILP (printcharfun)) \ 201 if (NILP (printcharfun)) \
@@ -196,7 +207,8 @@ glyph_to_str_cpy (glyphs, str)
196 SET_PT (old_point + (old_point >= start_point \ 207 SET_PT (old_point + (old_point >= start_point \
197 ? PT - start_point : 0)); \ 208 ? PT - start_point : 0)); \
198 if (old != current_buffer) \ 209 if (old != current_buffer) \
199 set_buffer_internal (old) 210 set_buffer_internal (old); \
211 printed_gensyms = Qnil
200 212
201#define PRINTCHAR(ch) printchar (ch, printcharfun) 213#define PRINTCHAR(ch) printchar (ch, printcharfun)
202 214
@@ -366,10 +378,7 @@ PRINTCHARFUN defaults to the value of `standard-output' (which see).")
366 (character, printcharfun) 378 (character, printcharfun)
367 Lisp_Object character, printcharfun; 379 Lisp_Object character, printcharfun;
368{ 380{
369 struct buffer *old = current_buffer; 381 PRINTDECLARE;
370 int old_point = -1;
371 int start_point;
372 Lisp_Object original;
373 382
374 if (NILP (printcharfun)) 383 if (NILP (printcharfun))
375 printcharfun = Vstandard_output; 384 printcharfun = Vstandard_output;
@@ -388,11 +397,8 @@ write_string (data, size)
388 char *data; 397 char *data;
389 int size; 398 int size;
390{ 399{
391 struct buffer *old = current_buffer; 400 PRINTDECLARE;
392 Lisp_Object printcharfun; 401 Lisp_Object printcharfun;
393 int old_point = -1;
394 int start_point;
395 Lisp_Object original;
396 402
397 printcharfun = Vstandard_output; 403 printcharfun = Vstandard_output;
398 404
@@ -410,10 +416,7 @@ write_string_1 (data, size, printcharfun)
410 int size; 416 int size;
411 Lisp_Object printcharfun; 417 Lisp_Object printcharfun;
412{ 418{
413 struct buffer *old = current_buffer; 419 PRINTDECLARE;
414 int old_point = -1;
415 int start_point;
416 Lisp_Object original;
417 420
418 PRINTPREPARE; 421 PRINTPREPARE;
419 strout (data, size, printcharfun); 422 strout (data, size, printcharfun);
@@ -509,10 +512,7 @@ If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used.")
509 (printcharfun) 512 (printcharfun)
510 Lisp_Object printcharfun; 513 Lisp_Object printcharfun;
511{ 514{
512 struct buffer *old = current_buffer; 515 PRINTDECLARE;
513 int old_point = -1;
514 int start_point;
515 Lisp_Object original;
516 516
517 if (NILP (printcharfun)) 517 if (NILP (printcharfun))
518 printcharfun = Vstandard_output; 518 printcharfun = Vstandard_output;
@@ -530,10 +530,7 @@ Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
530 (object, printcharfun) 530 (object, printcharfun)
531 Lisp_Object object, printcharfun; 531 Lisp_Object object, printcharfun;
532{ 532{
533 struct buffer *old = current_buffer; 533 PRINTDECLARE;
534 int old_point = -1;
535 int start_point;
536 Lisp_Object original;
537 534
538#ifdef MAX_PRINT_CHARS 535#ifdef MAX_PRINT_CHARS
539 max_print = 0; 536 max_print = 0;
@@ -558,10 +555,8 @@ second argument NOESCAPE is non-nil.")
558 (object, noescape) 555 (object, noescape)
559 Lisp_Object object, noescape; 556 Lisp_Object object, noescape;
560{ 557{
561 struct buffer *old = current_buffer; 558 PRINTDECLARE;
562 int old_point = -1; 559 Lisp_Object printcharfun;
563 int start_point;
564 Lisp_Object original, printcharfun;
565 struct gcpro gcpro1, gcpro2; 560 struct gcpro gcpro1, gcpro2;
566 Lisp_Object tem; 561 Lisp_Object tem;
567 562
@@ -597,10 +592,7 @@ Output stream is PRINTCHARFUN, or value of standard-output (which see).")
597 (object, printcharfun) 592 (object, printcharfun)
598 Lisp_Object object, printcharfun; 593 Lisp_Object object, printcharfun;
599{ 594{
600 struct buffer *old = current_buffer; 595 PRINTDECLARE;
601 int old_point = -1;
602 int start_point;
603 Lisp_Object original;
604 596
605 if (NILP (printcharfun)) 597 if (NILP (printcharfun))
606 printcharfun = Vstandard_output; 598 printcharfun = Vstandard_output;
@@ -619,10 +611,7 @@ Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
619 (object, printcharfun) 611 (object, printcharfun)
620 Lisp_Object object, printcharfun; 612 Lisp_Object object, printcharfun;
621{ 613{
622 struct buffer *old = current_buffer; 614 PRINTDECLARE;
623 int old_point = -1;
624 int start_point;
625 Lisp_Object original;
626 struct gcpro gcpro1; 615 struct gcpro gcpro1;
627 616
628#ifdef MAX_PRINT_CHARS 617#ifdef MAX_PRINT_CHARS
@@ -978,6 +967,39 @@ print (obj, printcharfun, escapeflag)
978 confusing = (end == p); 967 confusing = (end == p);
979 } 968 }
980 969
970 /* If we print an uninterned symbol as part of a complex object and
971 the flag print-gensym is non-nil, prefix it with #n= to read the
972 object back with the #n# reader syntax later if needed. */
973 if (print_gensym && NILP (XSYMBOL (obj)->obarray))
974 {
975 if (print_depth > 1)
976 {
977 Lisp_Object tem;
978 tem = Fassq (obj, printed_gensyms);
979 if (CONSP (tem))
980 {
981 PRINTCHAR ('#');
982 print (XCDR (tem), printcharfun, escapeflag);
983 PRINTCHAR ('#');
984 break;
985 }
986 else
987 {
988 if (CONSP (printed_gensyms))
989 XSETFASTINT (tem, XCDR (XCAR (printed_gensyms)) + 1);
990 else
991 XSETFASTINT (tem, 1);
992 printed_gensyms = Fcons (Fcons (obj, tem), printed_gensyms);
993
994 PRINTCHAR ('#');
995 print (tem, printcharfun, escapeflag);
996 PRINTCHAR ('=');
997 }
998 }
999 PRINTCHAR ('#');
1000 PRINTCHAR (':');
1001 }
1002
981 p = XSYMBOL (obj)->name->data; 1003 p = XSYMBOL (obj)->name->data;
982 while (p != end) 1004 while (p != end)
983 { 1005 {
@@ -1397,6 +1419,11 @@ I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
1397forms print in the new syntax."); 1419forms print in the new syntax.");
1398 print_quoted = 0; 1420 print_quoted = 0;
1399 1421
1422 DEFVAR_BOOL ("print-gensym", &print_gensym,
1423 "Non-nil means print uninterned symbols so they will read as uninterned.\n\
1424I.e., the value of (make-symbol "foobar") prints as #:foobar.");
1425 print_gensym = 0;
1426
1400 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ 1427 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
1401 staticpro (&Vprin1_to_string_buffer); 1428 staticpro (&Vprin1_to_string_buffer);
1402 1429
@@ -1415,8 +1442,8 @@ forms print in the new syntax.");
1415 Qprint_escape_newlines = intern ("print-escape-newlines"); 1442 Qprint_escape_newlines = intern ("print-escape-newlines");
1416 staticpro (&Qprint_escape_newlines); 1443 staticpro (&Qprint_escape_newlines);
1417 1444
1418 Qprint_quoted = intern ("print-quoted"); 1445 staticpro (&printed_gensyms);
1419 staticpro (&Qprint_quoted); 1446 printed_gensyms = Qnil;
1420 1447
1421#ifndef standalone 1448#ifndef standalone
1422 defsubr (&Swith_output_to_temp_buffer); 1449 defsubr (&Swith_output_to_temp_buffer);