comparison src/print.c @ 18961:e537071624ee

(Vprint_gensym_alist): Renamed from printed_gensyms. (Vprint_gensym): Now a Lisp_Object; Renamed from print_gensym. (syms_of_print): Set up both as Lisp vars. (PRINTPREPARE, PRINTFINISH): Don't clear Vprint_gensym_alist if Vprint_gensym is a cons cell.
author Richard M. Stallman <rms@gnu.org>
date Fri, 25 Jul 1997 03:04:19 +0000
parents 614b916ff5bf
children 2190c39dc640
comparison
equal deleted inserted replaced
18960:12a8bc6cb225 18961:e537071624ee
81 81
82 /* Nonzero means print (quote foo) forms as 'foo, etc. */ 82 /* Nonzero means print (quote foo) forms as 'foo, etc. */
83 83
84 int print_quoted; 84 int print_quoted;
85 85
86 /* Nonzero means print #: before uninterned symbols. */ 86 /* Non-nil means print #: before uninterned symbols.
87 87 Neither t nor nil means so that and don't clear Vprint_gensym_alist
88 int print_gensym; 88 on entry to and exit from print functions. */
89
90 Lisp_Object Vprint_gensym;
89 91
90 /* Association list of certain objects that are `eq' in the form being 92 /* Association list of certain objects that are `eq' in the form being
91 printed and which should be `eq' when read back in, using the #n=object 93 printed and which should be `eq' when read back in, using the #n=object
92 and #n# reader forms. Each element has the form (object . n). */ 94 and #n# reader forms. Each element has the form (object . n). */
93 95
94 Lisp_Object printed_gensyms; 96 Lisp_Object Vprint_gensym_alist;
95 97
96 /* Nonzero means print newline to stdout before next minibuffer message. 98 /* Nonzero means print newline to stdout before next minibuffer message.
97 Defined in xdisp.c */ 99 Defined in xdisp.c */
98 100
99 extern int noninteractive_need_newline; 101 extern int noninteractive_need_newline;
206 print_buffer = (char *) xmalloc (print_buffer_size); \ 208 print_buffer = (char *) xmalloc (print_buffer_size); \
207 free_print_buffer = 1; \ 209 free_print_buffer = 1; \
208 } \ 210 } \
209 print_buffer_pos = 0; \ 211 print_buffer_pos = 0; \
210 } \ 212 } \
211 printed_gensyms = Qnil 213 if (!CONSP (Vprint_gensym)) \
214 Vprint_gensym_alist = Qnil
212 215
213 #define PRINTFINISH \ 216 #define PRINTFINISH \
214 if (NILP (printcharfun)) \ 217 if (NILP (printcharfun)) \
215 insert (print_buffer, print_buffer_pos); \ 218 insert (print_buffer, print_buffer_pos); \
216 if (free_print_buffer) \ 219 if (free_print_buffer) \
224 if (old_point >= 0) \ 227 if (old_point >= 0) \
225 SET_PT (old_point + (old_point >= start_point \ 228 SET_PT (old_point + (old_point >= start_point \
226 ? PT - start_point : 0)); \ 229 ? PT - start_point : 0)); \
227 if (old != current_buffer) \ 230 if (old != current_buffer) \
228 set_buffer_internal (old); \ 231 set_buffer_internal (old); \
229 printed_gensyms = Qnil 232 if (!CONSP (Vprint_gensym)) \
233 Vprint_gensym_alist = Qnil
230 234
231 #define PRINTCHAR(ch) printchar (ch, printcharfun) 235 #define PRINTCHAR(ch) printchar (ch, printcharfun)
232 236
233 /* Nonzero if there is no room to print any more characters 237 /* Nonzero if there is no room to print any more characters
234 so print might as well return right away. */ 238 so print might as well return right away. */
1045 confusing = 0; 1049 confusing = 0;
1046 1050
1047 /* If we print an uninterned symbol as part of a complex object and 1051 /* If we print an uninterned symbol as part of a complex object and
1048 the flag print-gensym is non-nil, prefix it with #n= to read the 1052 the flag print-gensym is non-nil, prefix it with #n= to read the
1049 object back with the #n# reader syntax later if needed. */ 1053 object back with the #n# reader syntax later if needed. */
1050 if (print_gensym && NILP (XSYMBOL (obj)->obarray)) 1054 if (! NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
1051 { 1055 {
1052 if (print_depth > 1) 1056 if (print_depth > 1)
1053 { 1057 {
1054 Lisp_Object tem; 1058 Lisp_Object tem;
1055 tem = Fassq (obj, printed_gensyms); 1059 tem = Fassq (obj, Vprint_gensym_alist);
1056 if (CONSP (tem)) 1060 if (CONSP (tem))
1057 { 1061 {
1058 PRINTCHAR ('#'); 1062 PRINTCHAR ('#');
1059 print (XCDR (tem), printcharfun, escapeflag); 1063 print (XCDR (tem), printcharfun, escapeflag);
1060 PRINTCHAR ('#'); 1064 PRINTCHAR ('#');
1061 break; 1065 break;
1062 } 1066 }
1063 else 1067 else
1064 { 1068 {
1065 if (CONSP (printed_gensyms)) 1069 if (CONSP (Vprint_gensym_alist))
1066 XSETFASTINT (tem, XFASTINT (XCDR (XCAR (printed_gensyms))) + 1); 1070 XSETFASTINT (tem, XFASTINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
1067 else 1071 else
1068 XSETFASTINT (tem, 1); 1072 XSETFASTINT (tem, 1);
1069 printed_gensyms = Fcons (Fcons (obj, tem), printed_gensyms); 1073 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
1070 1074
1071 PRINTCHAR ('#'); 1075 PRINTCHAR ('#');
1072 print (tem, printcharfun, escapeflag); 1076 print (tem, printcharfun, escapeflag);
1073 PRINTCHAR ('='); 1077 PRINTCHAR ('=');
1074 } 1078 }
1503 "Non-nil means print quoted forms with reader syntax.\n\ 1507 "Non-nil means print quoted forms with reader syntax.\n\
1504 I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\ 1508 I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
1505 forms print in the new syntax."); 1509 forms print in the new syntax.");
1506 print_quoted = 0; 1510 print_quoted = 0;
1507 1511
1508 DEFVAR_BOOL ("print-gensym", &print_gensym, 1512 DEFVAR_LISP ("print-gensym", &Vprint_gensym,
1509 "Non-nil means print uninterned symbols so they will read as uninterned.\n\ 1513 "Non-nil means print uninterned symbols so they will read as uninterned.\n\
1510 I.e., the value of (make-symbol "foobar") prints as #:foobar."); 1514 I.e., the value of (make-symbol "foobar") prints as #:foobar.\n\
1511 print_gensym = 0; 1515 When the uninterned symbol appears within a larger data structure,\n\
1516 in addition use the #...# and #...= constructs as needed,\n\
1517 so that multiple references to the same symbol are shared once again\n\
1518 when the text is read back.\n\
1519 \n\
1520 If the value of `print-gensym' is a cons cell, then in addition refrain from\n\
1521 clearing `print-gensym-alist' on entry to and exit from printing functions,\n\
1522 so that the use of #...# and #...= can carry over for several separately\n\
1523 printed objects.");
1524 Vprint_gensym = Qnil;
1525
1526 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist,
1527 "Association list of elements (GENSYM . N) to guide use of #N# and #N=.\n\
1528 In each element, GENSYM is an uninterned symbol that has been associated\n\
1529 with #N= for the specified value of N.");
1530 Vprint_gensym_alist = Qnil;
1512 1531
1513 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ 1532 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
1514 staticpro (&Vprin1_to_string_buffer); 1533 staticpro (&Vprin1_to_string_buffer);
1515 1534
1516 defsubr (&Sprin1); 1535 defsubr (&Sprin1);
1526 staticpro (&Qexternal_debugging_output); 1545 staticpro (&Qexternal_debugging_output);
1527 1546
1528 Qprint_escape_newlines = intern ("print-escape-newlines"); 1547 Qprint_escape_newlines = intern ("print-escape-newlines");
1529 staticpro (&Qprint_escape_newlines); 1548 staticpro (&Qprint_escape_newlines);
1530 1549
1531 staticpro (&printed_gensyms);
1532 printed_gensyms = Qnil;
1533
1534 #ifndef standalone 1550 #ifndef standalone
1535 defsubr (&Swith_output_to_temp_buffer); 1551 defsubr (&Swith_output_to_temp_buffer);
1536 #endif /* not standalone */ 1552 #endif /* not standalone */
1537 } 1553 }