home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / bytecomp / print.c.patch < prev    next >
Encoding:
Text File  |  1991-10-29  |  6.7 KB  |  234 lines

  1. *** old-print.c    Sun Jul 28 14:57:00 1991
  2. --- print.c    Mon Oct 28 23:46:18 1991
  3. ***************
  4. *** 52,59 ****
  5. --- 52,61 ----
  6.   /* Nonzero means print newlines in strings as \n.  */
  7.   
  8.   int print_escape_newlines;
  9. + int print_readably;
  10.   
  11.   Lisp_Object Qprint_escape_newlines;
  12. + Lisp_Object Qprint_readably;
  13.   
  14.   /* Nonzero means print newline before next minibuffer message.
  15.      Defined in xdisp.c */
  16. ***************
  17. *** 608,613 ****
  18. --- 610,617 ----
  19.   #endif
  20.       {
  21.       default:
  22. +       if (print_readably)
  23. +     error ("printing illegal data type #o%3o", (int) XTYPE (obj));
  24.         /* We're in trouble if this happens!
  25.        Probably should just abort () */
  26.         strout ("#<EMACS BUG: ILLEGAL DATATYPE ", -1, printcharfun);
  27. ***************
  28. *** 670,675 ****
  29. --- 674,693 ----
  30.       register unsigned char *end = p + XSYMBOL (obj)->name->size;
  31.       register unsigned char c;
  32.   
  33. + #if 0
  34. +     /* This is a dangerous and certainly-doesn't-do-what-you-meant kind of
  35. +        thing to do, but there's quite a lot of code out there that does this,
  36. +        so let it slide for now...
  37. +      */
  38. +     if (print_readably) {
  39. +       Lisp_Object tem = oblookup (Vobarray, p, end-p);
  40. +       if (!EQ (tem, obj))
  41. +         /* (read) would return a new symbol with the same name. */
  42. +         error ("printing an uninterned symbol named \"%s\"", p);
  43. +     }
  44. + #endif
  45.       if (p != end && (*p == '-' || *p == '+')) p++;
  46.           if (p == end)
  47.         confusing = 0;
  48. ***************
  49. *** 706,711 ****
  50. --- 724,739 ----
  51.         break;
  52.       }
  53.   
  54. +       /* If Vprint_readably is on, print (quote -foo-) as '-foo- */
  55. +       if (print_readably &&
  56. +       EQ (XCONS (obj)->car, Qquote) &&
  57. +       XTYPE (XCONS (obj)->cdr) == Lisp_Cons &&
  58. +       NULL (XCONS (XCONS (obj)->cdr)->cdr)) {
  59. +     PRINTCHAR ('\'');
  60. +     print (XCONS (XCONS (obj)->cdr)->car, printcharfun, escapeflag);
  61. +     break;
  62. +       }
  63.         PRINTCHAR ('(');
  64.         {
  65.       register int i = 0;
  66. ***************
  67. *** 735,741 ****
  68.         break;
  69.   
  70.       case Lisp_Compiled:
  71. !       strout ("#<byte-code ", -1, printcharfun);
  72.       case Lisp_Vector:
  73.         PRINTCHAR ('[');
  74.         {
  75. --- 763,769 ----
  76.         break;
  77.   
  78.       case Lisp_Compiled:
  79. !       strout ((print_readably ? "#" : "#<byte-code "), -1, printcharfun);
  80.       case Lisp_Vector:
  81.         PRINTCHAR ('[');
  82.         {
  83. ***************
  84. *** 749,755 ****
  85.         }
  86.         }
  87.         PRINTCHAR (']');
  88. !       if (XTYPE (obj) == Lisp_Compiled)
  89.       PRINTCHAR ('>');
  90.         break;
  91.   
  92. --- 777,783 ----
  93.         }
  94.         }
  95.         PRINTCHAR (']');
  96. !       if (!print_readably && XTYPE (obj) == Lisp_Compiled)
  97.       PRINTCHAR ('>');
  98.         break;
  99.   
  100. ***************
  101. *** 757,762 ****
  102. --- 785,794 ----
  103.       case Lisp_Interval:
  104.         if (escapeflag)
  105.       {
  106. +       if (print_readably)
  107. +         error ("printing unreadable object #<interval [%d %d]>",
  108. +            XINTERVAL (obj)->position, XINTERVAL (obj)->my_length);
  109. +       
  110.         strout ("#<interval ", -1, printcharfun);
  111.         sprintf (buf, "[%d, %d]", XINTERVAL (obj)->position,
  112.              XINTERVAL (obj)->my_length);
  113. ***************
  114. *** 779,784 ****
  115. --- 811,823 ----
  116.         break;
  117.   
  118.       case Lisp_Buffer:
  119. +       if (print_readably) {
  120. +     if (NULL (XBUFFER (obj)->name))
  121. +       error ("printing unreadable object #<killed buffer>");
  122. +     else
  123. +       error ("printing unreadable object #<buffer %s>",
  124. +          XSTRING (XBUFFER (obj)->name)->data);
  125. +       }
  126.         if (NULL (XBUFFER (obj)->name))
  127.       strout ("#<killed buffer>", -1, printcharfun);
  128.         else if (escapeflag)
  129. ***************
  130. *** 794,799 ****
  131. --- 833,842 ----
  132.       case Lisp_Process:
  133.         if (escapeflag)
  134.       {
  135. +       if (print_readably)
  136. +         error ("printing unreadable object #<process %s>",
  137. +            XSTRING (XPROCESS (obj)->name)->data);
  138. +       
  139.         strout ("#<process ", -1, printcharfun);
  140.         strout (XSTRING (XPROCESS (obj)->name)->data, -1, printcharfun);
  141.         PRINTCHAR ('>');
  142. ***************
  143. *** 803,808 ****
  144. --- 846,855 ----
  145.         break;
  146.   
  147.       case Lisp_Window:
  148. +       if (print_readably)
  149. +     error ("printing unreadable object #<window %d>",
  150. +            XFASTINT (XWINDOW (obj)->sequence_number));
  151.         strout ("#<window ", -1, printcharfun);
  152.         sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number));
  153.         strout (buf, -1, printcharfun);
  154. ***************
  155. *** 816,826 ****
  156. --- 863,880 ----
  157.         break;
  158.   
  159.       case Lisp_Window_Configuration:
  160. +       if (print_readably)
  161. +     error ("printing unreadable object #<window-configuration>");
  162.         strout ("#<window-configuration>", -1, printcharfun);
  163.         break;
  164.   
  165.   #ifdef MULTI_SCREEN
  166.       case Lisp_Screen:
  167. +       if (print_readably)
  168. +     error ("printing unreadable object #<screen %s 0x%x>",
  169. +            XSTRING (XSCREEN (obj)->name)->data,
  170. +            XFASTINT (XSCREEN (obj)));
  171. +       
  172.         strout ("#<screen ", -1, printcharfun);
  173.         strout (XSTRING (XSCREEN (obj)->name)->data, -1, printcharfun);
  174.         sprintf (buf, " 0x%x", XFASTINT (XSCREEN (obj)));
  175. ***************
  176. *** 830,835 ****
  177. --- 884,892 ----
  178.   #endif /* MULTI_SCREEN */
  179.   
  180.       case Lisp_Marker:
  181. +       if (print_readably)
  182. +     error ("printing unreadable object #<marker>");
  183. +       
  184.         strout ("#<marker ", -1, printcharfun);
  185.         if (!(XMARKER (obj)->buffer))
  186.       strout ("in no buffer", -1, printcharfun);
  187. ***************
  188. *** 845,850 ****
  189. --- 902,911 ----
  190.   #endif /* standalone */
  191.   
  192.       case Lisp_Subr:
  193. +       if (print_readably)
  194. +     error ("printing unreadable object #<subr %s>",
  195. +            XSUBR (obj)->symbol_name);
  196. +       
  197.         strout ("#<subr ", -1, printcharfun);
  198.         strout (XSUBR (obj)->symbol_name, -1, printcharfun);
  199.         PRINTCHAR ('>');
  200. ***************
  201. *** 859,864 ****
  202. --- 920,927 ----
  203.   {
  204.     staticpro (&Qprint_escape_newlines);
  205.     Qprint_escape_newlines = intern ("print-escape-newlines");
  206. +   staticpro (&Qprint_readably);
  207. +   Qprint_readably = intern ("print-readably");
  208.   
  209.     DEFVAR_LISP ("standard-output", &Vstandard_output,
  210.       "Output stream `print' uses by default for outputting a character.\n\
  211. ***************
  212. *** 903,908 ****
  213. --- 966,981 ----
  214.     DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines,
  215.       "Non-nil means print newlines in strings as backslash-n.");
  216.     print_escape_newlines = 0;
  217. +   DEFVAR_BOOL ("print-readably", &print_readably,
  218. +     "If non-nil, then compiled-function objects will be written with\n#\
  219. + [...] syntax instead of #<byte-code [...]> syntax.  Lists of the form\n\
  220. + (quote -symbol-) will be printed with the more compact representation of\n\
  221. + '-symbol- instead.  Also, an error will be signalled if there is an\n\
  222. + attempt to write out any object whose printed representation is not\n\
  223. + readable (such as things that print in #<...> form).\n\
  224. + Do not SET this variable; bind it instead.");
  225. +   print_readably = 0;
  226.   
  227.     /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
  228.     staticpro (&Vprin1_to_string_buffer);
  229.