emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

list-print-separator (was: entry separator for printing hashtables)


From: Ted Zlatanov
Subject: list-print-separator (was: entry separator for printing hashtables)
Date: Thu, 21 Apr 2011 18:17:37 -0500
User-agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux)

On Wed, 06 Apr 2011 05:59:48 -0500 Ted Zlatanov <address@hidden> wrote: 

TZ> Since hashtables can get pretty big, it would be nice to have a
TZ> separator between entries when they are printed.  Could that be provided
TZ> at the top level, e.g.

TZ> (let ((hash-table-print-separator "\\\n"))
TZ>    (format "%S" my-hash-table))

TZ> or in some other way?  It would make large hashtable dumps like the ones
TZ> from the new registry.el and gnus-registry.el much easier to read and
TZ> debug.  In the old gnus-registry.el I had special code to break up
TZ> alists like that but it was slow so I'd rather ask Emacs to do it for
TZ> me at the C level.

The attached patch introduces `list-print-separator' to be used for list
and hashtable entries.  It's printed unescaped.  It could be a function
too, to be called with the print level.  For me it's sufficient as a
simple object to be printed.

Let me know what you think...

Thanks
Ted

=== modified file 'src/print.c'
--- src/print.c 2011-04-14 07:09:45 +0000
+++ src/print.c 2011-04-21 23:12:46 +0000
@@ -1658,6 +1658,10 @@
 
                print_object (XCAR (obj), printcharfun, escapeflag);
 
+                /* Separate entries with list-print-separator.  */
+                if (!NILP (Vlist_print_separator))
+                  print_object (Vlist_print_separator, printcharfun, 0);
+
                obj = XCDR (obj);
                if (!(i & 1))
                  halftail = XCDR (halftail);
@@ -1849,6 +1853,9 @@
                print_object (HASH_KEY (h, i), printcharfun, escapeflag);
                PRINTCHAR (' ');
                print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
+                /* Separate entries with list-print-separator.  */
+                if (!NILP (Vlist_print_separator))
+                  print_object (Vlist_print_separator, printcharfun, 0);
              }
 
          if (size < real_size)
@@ -2108,6 +2115,11 @@
 A value of nil means no limit.  See also `eval-expression-print-level'.  */);
   Vprint_level = Qnil;
 
+  DEFVAR_LISP ("list-print-separator", Vlist_print_separator,
+              doc: /* When non-nil, printed unescaped to separate list entries.
+Used for hashtable entries as well.  */);
+  Vlist_print_separator = Qnil;
+
   DEFVAR_BOOL ("print-escape-newlines", print_escape_newlines,
               doc: /* Non-nil means print newlines in strings as `\\n'.
 Also print formfeeds as `\\f'.  */);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]