From: Mattias EngdegÄrd Date: Thu, 2 Nov 2023 10:10:24 +0000 (+0100) Subject: * src/print.c (print_object): Don't print empty hash-table data X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a09619f2598a1658feac6794e85bc61a07c4855f;p=emacs.git * src/print.c (print_object): Don't print empty hash-table data Since no data is the default, this preserves bidirectional compatibility. --- diff --git a/src/print.c b/src/print.c index 0a5f2ee48d4..d011962d85b 100644 --- a/src/print.c +++ b/src/print.c @@ -2603,21 +2603,30 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) if (h->purecopy) print_c_string (" purecopy t", printcharfun); - print_c_string (" data (", printcharfun); - ptrdiff_t size = h->count; - /* Don't print more elements than the specified maximum. */ - if (FIXNATP (Vprint_length) && XFIXNAT (Vprint_length) < size) - size = XFIXNAT (Vprint_length); - - print_stack_push ((struct print_stack_entry){ - .type = PE_hash, - .u.hash.obj = obj, - .u.hash.nobjs = size * 2, - .u.hash.idx = 0, - .u.hash.printed = 0, - .u.hash.truncated = (size < h->count), - }); + if (size > 0) + { + print_c_string (" data (", printcharfun); + + /* Don't print more elements than the specified maximum. */ + if (FIXNATP (Vprint_length) && XFIXNAT (Vprint_length) < size) + size = XFIXNAT (Vprint_length); + + print_stack_push ((struct print_stack_entry){ + .type = PE_hash, + .u.hash.obj = obj, + .u.hash.nobjs = size * 2, + .u.hash.idx = 0, + .u.hash.printed = 0, + .u.hash.truncated = (size < h->count), + }); + } + else + { + /* Empty table: we can omit the data entirely. */ + printchar (')', printcharfun); + --print_depth; /* Done with this. */ + } goto next_obj; } diff --git a/test/src/print-tests.el b/test/src/print-tests.el index aedaa9a4e06..ff3a6fe7483 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el @@ -367,13 +367,6 @@ otherwise, use a different charset." (remhash 1 h) (format "%S" h)))) - (should - (string-match - "data ()" - (let ((h (make-hash-table))) - (let ((print-length 0)) - (format "%S" h))))) - (should (string-match "data (99 99)"