aboutsummaryrefslogtreecommitdiffstats
path: root/src/print.c
diff options
context:
space:
mode:
authorTeodor Zlatanov2009-08-05 09:19:21 +0000
committerTeodor Zlatanov2009-08-05 09:19:21 +0000
commitf19a0f5b11e41baf46ce11fd447744ceb97ef754 (patch)
treed770ff782b6b974389b8188b81b898133ddfca51 /src/print.c
parent74edaf1f3e6b0ff6669d481162cdd62828997f17 (diff)
downloademacs-f19a0f5b11e41baf46ce11fd447744ceb97ef754.tar.gz
emacs-f19a0f5b11e41baf46ce11fd447744ceb97ef754.zip
* lread.c (read1, syms_of_lread): Read hashtables back from the
readable format. * print.c (print_preprocess, print_object): Print hashtables fully and readably. (syms_of_print): Provide 'hashtable-print-readable.
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c
index e78f593c7b5..ce63b63acd3 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1341,6 +1341,7 @@ print_preprocess (obj)
1341 loop: 1341 loop:
1342 if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) 1342 if (STRINGP (obj) || CONSP (obj) || VECTORP (obj)
1343 || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) 1343 || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj)
1344 || HASH_TABLE_P (obj)
1344 || (! NILP (Vprint_gensym) 1345 || (! NILP (Vprint_gensym)
1345 && SYMBOLP (obj) 1346 && SYMBOLP (obj)
1346 && !SYMBOL_INTERNED_P (obj))) 1347 && !SYMBOL_INTERNED_P (obj)))
@@ -1536,6 +1537,7 @@ print_object (obj, printcharfun, escapeflag)
1536 /* Detect circularities and truncate them. */ 1537 /* Detect circularities and truncate them. */
1537 if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) 1538 if (STRINGP (obj) || CONSP (obj) || VECTORP (obj)
1538 || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) 1539 || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj)
1540 || HASH_TABLE_P (obj)
1539 || (! NILP (Vprint_gensym) 1541 || (! NILP (Vprint_gensym)
1540 && SYMBOLP (obj) 1542 && SYMBOLP (obj)
1541 && !SYMBOL_INTERNED_P (obj))) 1543 && !SYMBOL_INTERNED_P (obj)))
@@ -2031,6 +2033,7 @@ print_object (obj, printcharfun, escapeflag)
2031 else if (HASH_TABLE_P (obj)) 2033 else if (HASH_TABLE_P (obj))
2032 { 2034 {
2033 struct Lisp_Hash_Table *h = XHASH_TABLE (obj); 2035 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
2036#if 0
2034 strout ("#<hash-table", -1, -1, printcharfun, 0); 2037 strout ("#<hash-table", -1, -1, printcharfun, 0);
2035 if (SYMBOLP (h->test)) 2038 if (SYMBOLP (h->test))
2036 { 2039 {
@@ -2047,6 +2050,67 @@ print_object (obj, printcharfun, escapeflag)
2047 sprintf (buf, " 0x%lx", (unsigned long) h); 2050 sprintf (buf, " 0x%lx", (unsigned long) h);
2048 strout (buf, -1, -1, printcharfun, 0); 2051 strout (buf, -1, -1, printcharfun, 0);
2049 PRINTCHAR ('>'); 2052 PRINTCHAR ('>');
2053#endif
2054 /* Implement a readable output, e.g.:
2055 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
2056 /* Always print the size. */
2057 sprintf (buf, "#s(hash-table size %ld",
2058 (long) XVECTOR (h->next)->size);
2059 strout (buf, -1, -1, printcharfun, 0);
2060
2061 if (!NILP (h->test))
2062 {
2063 strout (" test ", -1, -1, printcharfun, 0);
2064 print_object (h->test, printcharfun, 0);
2065 }
2066
2067 if (!NILP (h->weak))
2068 {
2069 strout (" weakness ", -1, -1, printcharfun, 0);
2070 print_object (h->weak, printcharfun, 0);
2071 }
2072
2073 if (!NILP (h->rehash_size))
2074 {
2075 strout (" rehash-size ", -1, -1, printcharfun, 0);
2076 print_object (h->rehash_size, printcharfun, 0);
2077 }
2078
2079 if (!NILP (h->rehash_threshold))
2080 {
2081 strout (" rehash-threshold ", -1, -1, printcharfun, 0);
2082 print_object (h->rehash_threshold, printcharfun, 0);
2083 }
2084
2085 strout (" data ", -1, -1, printcharfun, 0);
2086
2087 /* Print the data here as a plist. */
2088 int i;
2089
2090 int real_size = HASH_TABLE_SIZE (h);
2091 int size = real_size;
2092
2093 /* Don't print more elements than the specified maximum. */
2094 if (NATNUMP (Vprint_length)
2095 && XFASTINT (Vprint_length) < size)
2096 size = XFASTINT (Vprint_length);
2097
2098 PRINTCHAR ('(');
2099 for (i = 0; i < size; i++)
2100 if (!NILP (HASH_HASH (h, i)))
2101 {
2102 if (i) PRINTCHAR (' ');
2103 print_object (HASH_KEY (h, i), printcharfun, 0);
2104 PRINTCHAR (' ');
2105 print_object (HASH_VALUE (h, i), printcharfun, 0);
2106 }
2107
2108 if (size < real_size)
2109 strout (" ...", 4, 4, printcharfun, 0);
2110
2111 PRINTCHAR (')');
2112 PRINTCHAR (')');
2113
2050 } 2114 }
2051 else if (BUFFERP (obj)) 2115 else if (BUFFERP (obj))
2052 { 2116 {
@@ -2354,6 +2418,8 @@ that represents the number without losing information. */);
2354 Qfloat_output_format = intern ("float-output-format"); 2418 Qfloat_output_format = intern ("float-output-format");
2355 staticpro (&Qfloat_output_format); 2419 staticpro (&Qfloat_output_format);
2356 2420
2421 Fprovide (intern ("hashtable-print-readable"), Qnil);
2422
2357 DEFVAR_LISP ("print-length", &Vprint_length, 2423 DEFVAR_LISP ("print-length", &Vprint_length,
2358 doc: /* Maximum length of list to print before abbreviating. 2424 doc: /* Maximum length of list to print before abbreviating.
2359A value of nil means no limit. See also `eval-expression-print-length'. */); 2425A value of nil means no limit. See also `eval-expression-print-length'. */);