Mercurial > hg > xemacs-beta
comparison src/print.c @ 245:51092a27c943 r20-5b21
Import from CVS: tag r20-5b21
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:17:54 +0200 |
parents | 52952cbfc5b5 |
children | 677f6a0ee643 |
comparison
equal
deleted
inserted
replaced
244:78d4f1140794 | 245:51092a27c943 |
---|---|
81 | 81 |
82 /* Nonzero means print newlines in strings as \n. */ | 82 /* Nonzero means print newlines in strings as \n. */ |
83 | 83 |
84 int print_escape_newlines; | 84 int print_escape_newlines; |
85 int print_readably; | 85 int print_readably; |
86 int print_gensym; | 86 |
87 /* Non-nil means print #: before uninterned symbols. | |
88 Neither t nor nil means so that and don't clear Vprint_gensym_alist | |
89 on entry to and exit from print functions. */ | |
90 Lisp_Object Vprint_gensym; | |
91 Lisp_Object Vprint_gensym_alist; | |
87 | 92 |
88 Lisp_Object Qprint_escape_newlines; | 93 Lisp_Object Qprint_escape_newlines; |
89 Lisp_Object Qprint_readably; | 94 Lisp_Object Qprint_readably; |
90 | 95 |
91 Lisp_Object Qdisplay_error; | 96 Lisp_Object Qdisplay_error; |
336 == Sexternal_debugging_output)) | 341 == Sexternal_debugging_output)) |
337 { | 342 { |
338 stdio_stream = stderr; | 343 stdio_stream = stderr; |
339 } | 344 } |
340 #endif | 345 #endif |
346 if (!CONSP (Vprint_gensym)) | |
347 Vprint_gensym_alist = Qnil; | |
341 | 348 |
342 return make_print_output_stream (stdio_stream, printcharfun); | 349 return make_print_output_stream (stdio_stream, printcharfun); |
343 } | 350 } |
344 | 351 |
345 static void | 352 static void |
346 print_finish (Lisp_Object stream) | 353 print_finish (Lisp_Object stream) |
347 { | 354 { |
348 /* Emacs won't print whilst GCing, but an external debugger might */ | 355 /* Emacs won't print whilst GCing, but an external debugger might */ |
349 if (gc_in_progress) | 356 if (gc_in_progress) |
350 return; | 357 return; |
358 | |
359 if (!CONSP (Vprint_gensym)) | |
360 Vprint_gensym_alist = Qnil; | |
351 | 361 |
352 Lstream_delete (XLSTREAM (stream)); | 362 Lstream_delete (XLSTREAM (stream)); |
353 } | 363 } |
354 | 364 |
355 #if 1 /* Prefer space over "speed" */ | 365 #if 1 /* Prefer space over "speed" */ |
891 if (max && i > max) | 901 if (max && i > max) |
892 { | 902 { |
893 write_c_string ("...", printcharfun); | 903 write_c_string ("...", printcharfun); |
894 break; | 904 break; |
895 } | 905 } |
896 print_internal (Fcar (obj), printcharfun, | 906 print_internal (XCAR (obj), printcharfun, |
897 escapeflag); | 907 escapeflag); |
898 obj = Fcdr (obj); | 908 obj = XCDR (obj); |
899 } | 909 } |
900 } | 910 } |
901 if (!NILP (obj) && !CONSP (obj)) | 911 if (!NILP (obj) && !CONSP (obj)) |
902 { | 912 { |
903 write_c_string (" . ", printcharfun); | 913 write_c_string (" . ", printcharfun); |
915 } | 925 } |
916 | 926 |
917 void | 927 void |
918 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | 928 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) |
919 { | 929 { |
920 Bytecount size = XSTRING_LENGTH (obj); | 930 struct Lisp_String *s = XSTRING (obj); |
931 /* We distinguish between Bytecounts and Charcounts, to make | |
932 Vprint_string_length work correctly under Mule. */ | |
933 Charcount size = string_char_length (s); | |
934 Charcount max = size; | |
935 Bytecount bcmax = string_length (s); | |
921 struct gcpro gcpro1, gcpro2; | 936 struct gcpro gcpro1, gcpro2; |
922 int max = size; | |
923 GCPRO2 (obj, printcharfun); | 937 GCPRO2 (obj, printcharfun); |
924 | 938 |
925 if (INTP (Vprint_string_length) && | 939 if (INTP (Vprint_string_length) && |
926 XINT (Vprint_string_length) < max) | 940 XINT (Vprint_string_length) < max) |
927 max = XINT (Vprint_string_length); | 941 { |
942 max = XINT (Vprint_string_length); | |
943 bcmax = charcount_to_bytecount (string_data (s), max); | |
944 } | |
928 if (max < 0) | 945 if (max < 0) |
929 max = 0; | 946 { |
930 | 947 max = 0; |
931 /* !!#### This handles MAX incorrectly for Mule. */ | 948 bcmax = 0; |
949 } | |
950 | |
932 if (!escapeflag) | 951 if (!escapeflag) |
933 { | 952 { |
934 /* This deals with GC-relocation */ | 953 /* This deals with GC-relocation and Mule. */ |
935 output_string (printcharfun, 0, obj, 0, max); | 954 output_string (printcharfun, 0, obj, 0, bcmax); |
936 if (max < size) | 955 if (max < size) |
937 write_c_string (" ...", printcharfun); | 956 write_c_string (" ...", printcharfun); |
938 } | 957 } |
939 else | 958 else |
940 { | 959 { |
941 Bytecount i; | 960 Bytecount i, last = 0; |
942 struct Lisp_String *s = XSTRING (obj); | |
943 Bytecount last = 0; | |
944 | 961 |
945 write_char_internal ("\"", printcharfun); | 962 write_char_internal ("\"", printcharfun); |
946 for (i = 0; i < max; i++) | 963 for (i = 0; i < bcmax; i++) |
947 { | 964 { |
948 Bufbyte ch = string_byte (s, i); | 965 Bufbyte ch = string_byte (s, i); |
949 if (ch == '\"' || ch == '\\' | 966 if (ch == '\"' || ch == '\\' |
950 || (ch == '\n' && print_escape_newlines)) | 967 || (ch == '\n' && print_escape_newlines)) |
951 { | 968 { |
967 printcharfun); | 984 printcharfun); |
968 } | 985 } |
969 last = i + 1; | 986 last = i + 1; |
970 } | 987 } |
971 } | 988 } |
972 if (max > last) | 989 if (bcmax > last) |
973 { | 990 { |
974 output_string (printcharfun, 0, obj, last, | 991 output_string (printcharfun, 0, obj, last, |
975 max - last); | 992 bcmax - last); |
976 } | 993 } |
977 if (max < size) | 994 if (max < size) |
978 write_c_string (" ...", printcharfun); | 995 write_c_string (" ...", printcharfun); |
979 write_char_internal ("\"", printcharfun); | 996 write_char_internal ("\"", printcharfun); |
980 } | 997 } |
1324 output_string (printcharfun, 0, nameobj, 0, size); | 1341 output_string (printcharfun, 0, nameobj, 0, size); |
1325 return; | 1342 return; |
1326 } | 1343 } |
1327 GCPRO2 (obj, printcharfun); | 1344 GCPRO2 (obj, printcharfun); |
1328 | 1345 |
1329 if (print_gensym) | 1346 /* If we print an uninterned symbol as part of a complex object and |
1330 { | 1347 the flag print-gensym is non-nil, prefix it with #n= to read the |
1331 Lisp_Object tem = oblookup (Vobarray, string_data (name), size); | 1348 object back with the #n# reader syntax later if needed. */ |
1332 if (!EQ (tem, obj)) | 1349 if (!NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray)) |
1333 /* (read) would return a new symbol with the same name. | 1350 { |
1334 This isn't quite correct, because that symbol might not | 1351 if (print_depth > 1) |
1335 really be uninterned (it might be interned in some other | 1352 { |
1336 obarray) but there's no way to win in that case without | 1353 Lisp_Object tem = Fassq (obj, Vprint_gensym_alist); |
1337 implementing a real package system. | 1354 if (CONSP (tem)) |
1338 */ | 1355 { |
1339 write_c_string ("#:", printcharfun); | 1356 write_char_internal ("#", printcharfun); |
1357 print_internal (XCDR (tem), printcharfun, escapeflag); | |
1358 write_char_internal ("#", printcharfun); | |
1359 return; | |
1360 } | |
1361 else | |
1362 { | |
1363 if (CONSP (Vprint_gensym_alist)) | |
1364 XSETINT (tem, XINT (XCDR (XCAR (Vprint_gensym_alist))) + 1); | |
1365 else | |
1366 XSETINT (tem, 1); | |
1367 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist); | |
1368 | |
1369 write_char_internal ("#", printcharfun); | |
1370 print_internal (tem, printcharfun, escapeflag); | |
1371 write_char_internal ("=", printcharfun); | |
1372 } | |
1373 } | |
1374 write_c_string ("#:", printcharfun); | |
1340 } | 1375 } |
1341 | 1376 |
1342 /* Does it look like an integer or a float? */ | 1377 /* Does it look like an integer or a float? */ |
1343 { | 1378 { |
1344 Bufbyte *data = string_data (name); | 1379 Bufbyte *data = string_data (name); |
1749 lists of the form (quote object) will be written as the equivalent 'object. | 1784 lists of the form (quote object) will be written as the equivalent 'object. |
1750 Do not SET this variable; bind it instead. | 1785 Do not SET this variable; bind it instead. |
1751 */ ); | 1786 */ ); |
1752 print_readably = 0; | 1787 print_readably = 0; |
1753 | 1788 |
1754 DEFVAR_BOOL ("print-gensym", &print_gensym /* | 1789 /* #### I think this should default to t. But we'd better wait |
1790 until we see that it works out. */ | |
1791 DEFVAR_LISP ("print-gensym", &Vprint_gensym /* | |
1755 If non-nil, then uninterned symbols will be printed specially. | 1792 If non-nil, then uninterned symbols will be printed specially. |
1756 Uninterned symbols are those which are not present in `obarray', that is, | 1793 Uninterned symbols are those which are not present in `obarray', that is, |
1757 those which were made with `make-symbol' or by calling `intern' with a | 1794 those which were made with `make-symbol' or by calling `intern' with a |
1758 second argument. | 1795 second argument. |
1759 | 1796 |
1760 When print-gensym is true, such symbols will be preceded by "#:", which | 1797 When print-gensym is true, such symbols will be preceded by "#:", |
1761 causes the reader to create a new symbol instead of interning and returning | 1798 which causes the reader to create a new symbol instead of interning |
1762 an existing one. Beware: the #: syntax creates a new symbol each time it is | 1799 and returning an existing one. Beware: the #: syntax creates a new |
1763 seen, so if you print an object which contains two pointers to the same | 1800 symbol each time it is seen, so if you print an object which contains |
1764 uninterned symbol, `read' will not duplicate that structure. | 1801 two pointers to the same uninterned symbol, `read' will not duplicate |
1765 | 1802 that structure. |
1766 Also, since XEmacs has no real notion of packages, there is no way for the | 1803 |
1767 printer to distinguish between symbols interned in no obarray, and symbols | 1804 If the value of `print-gensym' is a cons cell, then in addition |
1768 interned in an alternate obarray. | 1805 refrain from clearing `print-gensym-alist' on entry to and exit from |
1806 printing functions, so that the use of #...# and #...= can carry over | |
1807 for several separately printed objects. | |
1769 */ ); | 1808 */ ); |
1770 print_gensym = 0; | 1809 Vprint_gensym = Qnil; |
1810 | |
1811 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist /* | |
1812 Association list of elements (GENSYM . N) to guide use of #N# and #N=. | |
1813 In each element, GENSYM is an uninterned symbol that has been associated | |
1814 with #N= for the specified value of N. | |
1815 */ ); | |
1816 Vprint_gensym_alist = Qnil; | |
1771 | 1817 |
1772 DEFVAR_LISP ("print-message-label", &Vprint_message_label /* | 1818 DEFVAR_LISP ("print-message-label", &Vprint_message_label /* |
1773 Label for minibuffer messages created with `print'. This should | 1819 Label for minibuffer messages created with `print'. This should |
1774 generally be bound with `let' rather than set. (See `display-message'.) | 1820 generally be bound with `let' rather than set. (See `display-message'.) |
1775 */ ); | 1821 */ ); |