diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-07-31 06:15:16 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-07-31 06:15:16 -0700 |
commit | dbbfc2c41a3710bc64df7b477fcfa536da79233f (patch) | |
tree | e4527f7c82e8304c59b71792b10ee240f98eae61 /hash.c | |
parent | ab1a633e67d04bb36b2b00461e1a72a786bab917 (diff) | |
download | txr-dbbfc2c41a3710bc64df7b477fcfa536da79233f.tar.gz txr-dbbfc2c41a3710bc64df7b477fcfa536da79233f.tar.bz2 txr-dbbfc2c41a3710bc64df7b477fcfa536da79233f.zip |
Multi-line, indented printing of structure.
* eval.c (op_error): New static function.
(macro_form_p, fboundp): Static to external.
(special_operator_p): New function.
(eval_init): Register macrolet and symacrolet to op_error.
These are recognized and processed by expand, but we want
them in the op table so they are reported by special_operator_p.
* eval.h (fboundp, macro_form_p, special_operator_p): Declared.
* hash.c (print_key_val): Break long lines on spaces
between pairs with stream_width_check.
(hash_print_op): Implement split and indented printing.
* lib.c (obj_print_impl): New static function, resulting
from a merge of obj_print and obj_pprint. Fixes some
wrong-way recursion bugs: obj_pprint recursed into obj_print
in some places. Adds support for multi-line printing of
vectors and lists, with indentation using the new
interfaces in streams.
* stream.c (strm_base_init): Update initializer.
(put_indent, indent_mode_put_string): New static functions.
(put_string): Use indent_mode_put_string in either of the
two indent modes.
(put_char): Implement indent mode.
(get_indent_mode, test_set_indent_mode,
set_indent_mode, get_indent, set_indent,
inc_indent, width_check): New functions.
* stream.h (enum indent_mode): New.
(struct strm_base): indent_on member becomes indent_mode.
New members data_width and code_width.
(get_indent_mode, test_set_indent_mode,
set_indent_mode, get_indent, set_indent,
inc_indent, width_check): Declared.
* tests/009/json.expected: Updated.
* tests/010/seq.expected: Likewise.
* tests/011/macros-2.expected: Likewise.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -226,10 +226,12 @@ cnum cobj_hash_op(val obj) static val print_key_val(val out, val key, val value) { + width_check(out, chr(' ')); + if (value) - format(out, lit(" (~s ~s)"), key, value, nao); + format(out, lit("(~s ~s)"), key, value, nao); else - format(out, lit(" (~s)"), key, nao); + format(out, lit("(~s)"), key, nao); return nil; } @@ -349,15 +351,23 @@ static void hash_print_op(val hash, val out) { struct hash *h = coerce(struct hash *, hash->co.handle); int need_space = 0; + val save_mode = test_set_indent_mode(out, num_fast(indent_off), + num_fast(indent_data)); + val save_indent; + + put_string(lit("#H("), out); + + save_indent = inc_indent(out, zero); + + put_char(chr('('), out); - put_string(lit("#H(("), out); if (h->hash_fun == equal_hash) { obj_print(equal_based_k, out); need_space = 1; } if (h->flags != hash_weak_none) { if (need_space) - put_string(lit(" "), out); + put_char(chr(' '), out); switch (h->flags) { case hash_weak_both: obj_print(weak_keys_k, out); @@ -375,6 +385,9 @@ static void hash_print_op(val hash, val out) put_string(lit(")"), out); maphash(curry_123_23(func_n3(print_key_val), out), hash); put_string(lit(")"), out); + + set_indent_mode(out, save_mode); + set_indent(out, save_indent); } static void hash_mark(val hash) |