diff options
author | Andy Wingo <wingo@pobox.com> | 2011-12-04 22:37:27 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-12-04 22:37:27 +0100 |
commit | 8500b18696f5943049d769631b2abf309c98b3d2 (patch) | |
tree | e4c4acaf02927d071a725cd2e4460151b00a954d /libguile/print.c | |
parent | 2aef6c2ba990c5829004c28cd410ba26a74c0597 (diff) | |
download | guile-8500b18696f5943049d769631b2abf309c98b3d2.tar.gz |
new print option escape-newlines, defaults to #t
* libguile/private-options.h (SCM_PRINT_ESCAPE_NEWLINES_P):
* libguile/print.c: Add new escape-newlines print option, defaulting to
on.
(write_character): For newlines, if SCM_PRINT_ESCAPE_NEWLINES_P, then
print them as \n.
(scm_init_print): Refactor print options initialization.
Diffstat (limited to 'libguile/print.c')
-rw-r--r-- | libguile/print.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/libguile/print.c b/libguile/print.c index 4afd12c92..2551bdf91 100644 --- a/libguile/print.c +++ b/libguile/print.c @@ -107,8 +107,9 @@ scm_t_option scm_print_opts[] = { { SCM_OPTION_SCM, "quote-keywordish-symbols", (scm_t_bits)SCM_BOOL_F_BITS, "How to print symbols that have a colon as their first or last character. " "The value '#f' does not quote the colons; '#t' quotes them; " - "'reader' quotes them when the reader option 'keywords' is not '#f'." - }, + "'reader' quotes them when the reader option 'keywords' is not '#f'." }, + { SCM_OPTION_BOOLEAN, "escape-newlines", 1, + "Render newlines as \\n when printing using `write'." }, { 0 }, }; @@ -1119,6 +1120,12 @@ write_character (scm_t_wchar ch, SCM port, int string_escapes_p) display_character (ch, port, strategy); printed = 1; } + else if (ch == '\n' && SCM_PRINT_ESCAPE_NEWLINES_P) + { + display_character ('\\', port, iconveh_question_mark); + display_character ('n', port, strategy); + printed = 1; + } else if (ch == ' ' || ch == '\n') { display_character (ch, port, strategy); @@ -1529,13 +1536,6 @@ scm_init_print () { SCM vtable, layout, type; - scm_init_opts (scm_print_options, scm_print_opts); - - scm_print_options (scm_list_4 (scm_from_latin1_symbol ("highlight-prefix"), - scm_from_locale_string ("{"), - scm_from_latin1_symbol ("highlight-suffix"), - scm_from_locale_string ("}"))); - scm_gc_register_root (&print_state_pool); scm_gc_register_root (&scm_print_state_vtable); vtable = scm_make_vtable_vtable (scm_nullstr, SCM_INUM0, SCM_EOL); @@ -1551,6 +1551,11 @@ scm_init_print () #include "libguile/print.x" + scm_init_opts (scm_print_options, scm_print_opts); + scm_print_opts[SCM_PRINT_HIGHLIGHT_PREFIX_I].val = + SCM_UNPACK (scm_from_locale_string ("{")); + scm_print_opts[SCM_PRINT_HIGHLIGHT_SUFFIX_I].val = + SCM_UNPACK (scm_from_locale_string ("}")); scm_print_opts[SCM_PRINT_KEYWORD_STYLE_I].val = SCM_UNPACK (sym_reader); } |