diff options
author | Karl Berry <karl@freefriends.org> | 2020-01-23 17:54:16 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-01-23 17:54:16 +0000 |
commit | bdd44614e6b6436d84baa1d4ba136ced66ae8e0b (patch) | |
tree | bd4b1668b1e81181c354c53b22eed3344ac0c8df /Master/texmf-dist/tex/generic/scontents | |
parent | e1db097a0e2f5292da739738fc08b2659c7ceaab (diff) |
scontents (22jan20)
git-svn-id: svn://tug.org/texlive/trunk@53504 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/scontents')
-rw-r--r-- | Master/texmf-dist/tex/generic/scontents/scontents-code.tex | 176 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/scontents/scontents.tex | 6 |
2 files changed, 127 insertions, 55 deletions
diff --git a/Master/texmf-dist/tex/generic/scontents/scontents-code.tex b/Master/texmf-dist/tex/generic/scontents/scontents-code.tex index f417191f680..2901886b2e0 100644 --- a/Master/texmf-dist/tex/generic/scontents/scontents-code.tex +++ b/Master/texmf-dist/tex/generic/scontents/scontents-code.tex @@ -6,7 +6,7 @@ %% %% scontents.dtx (with options: `core') %% -%% Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> +%% Copyright (C) 2019-2020 by Pablo González L <pablgonz@educarchile.cl> %% %% This work may be distributed and/or modified under the conditions of the %% LaTeX Project Public License, either version 1.3c of this license or (at @@ -27,8 +27,10 @@ %% t-scontents.mkiv and %% scontents-code.tex. %% -\def\ScontentsCoreFileDate{2019-11-18}% +\def\ScontentsCoreFileDate{2020-01-21}% \begingroup + \catcode32=10 + \endlinechar=32 \def\next{\endgroup}% \expandafter\ifx\csname PackageError\endcsname\relax \begingroup @@ -50,23 +52,23 @@ }% \endgroup \endinput - } + }% \else \ifx\ScontentsFileDate\ScontentsCoreFileDate \else \def\next {% - \PackageError{scontents}{Mismatched~scontents~files~detected} + \PackageError{scontents}{Mismatched scontents files detected} {% - You~have~attempted~to~load~scontents~with~mismatched~files:~ - probably~you~have~one~or~more~files~'locally~installed'~which~ - are~in~conflict.~Loading~of~scontents~will~abort. + You have attempted to load scontents with mismatched files: + probably you have one or more files 'locally installed' which + are in conflict. Loading of scontents will abort. }% \endgroup \endinput }% \fi -\fi + \fi \next \keys_define:nn { scontents } { @@ -122,6 +124,7 @@ \bool_set_false:N \l__scontents_foreach_stop_bool \bool_new:N \l__scontents_foreach_wrapper_bool \bool_set_false:N \l__scontents_foreach_wrapper_bool +\bool_new:N \l__scontents_writable_bool \seq_new:N \l__scontents_foreach_print_seq \str_const:Nx \c__scontents_hidden_space_str { \c_percent_str \c_circumflex_str \c_circumflex_str A scheol \c_percent_str } @@ -160,12 +163,25 @@ } \keys_define:nn { scontents / Scontents } { - print-cmd .meta:nn = { scontents } { print-cmd = #1 }, - print-cmd .default:n = true, - store-cmd .meta:nn = { scontents } { store-cmd = #1 }, - force-eol .meta:nn = { scontents } { force-eol = #1 }, - force-eol .default:n = true, - unknown .code:n = { \__scontents_parse_command_keys:n {#1} } + write-cmd .code:n = { + \bool_set_true:N \l__scontents_writing_bool + \tl_set:Nn \l__scontents_fname_out_tl {#1} + }, + write-out .code:n = { + \bool_set_false:N \l__scontents_storing_bool + \bool_set_true:N \l__scontents_writing_bool + \tl_set:Nn \l__scontents_fname_out_tl {#1} + }, + write-env .value_required:n = true, + write-out .value_required:n = true, + print-cmd .meta:nn = { scontents } { print-cmd = #1 }, + print-cmd .default:n = true, + store-cmd .meta:nn = { scontents } { store-cmd = #1 }, + force-eol .meta:nn = { scontents } { force-eol = #1 }, + force-eol .default:n = true, + overwrite .meta:nn = { scontents } { overwrite = #1 }, + overwrite .default:n = true, + unknown .code:n = { \__scontents_parse_command_keys:n {#1} } } \keys_define:nn { scontents / foreachsc } { @@ -193,7 +209,7 @@ wrapper .code:n = { \bool_set_true:N \l__scontents_foreach_wrapper_bool \cs_set_protected:Npn - \__scontents_foreach_wrapper:n ##1 {#1} + \__scontents_foreach_wrapper:n ##1 {#1} }, wrapper .value_required:n = true, sep .tl_set:N = \l__scontents_foreach_sep_tl, @@ -281,6 +297,7 @@ \group_insert_after:N \tl_gclear:N \group_insert_after:N \g__scontents_temp_tl } +\cs_generate_variant:Nn \__scontents_lastfrom_seq:n { V } \cs_new_protected:Npn \__scontents_store_to_seq:NN #1#2 { \tl_log:N #1 @@ -311,7 +328,8 @@ \cs_new_protected:Npn \__scontents_env_generic_end: { \__scontents_stop_environment: - \__scontents_atend_environment: + \__scontents_finish_storing:NNN \l__scontents_macro_tmp_tl + \l__scontents_name_seq_env_tl \l__scontents_print_env_bool } \cs_new_protected:Npn \__scontents_grab_optional:n #1 { @@ -365,19 +383,12 @@ \cs_new_protected:Npn \__scontents_file_tl_write_start:n #1 { \group_begin: - \bool_if:nT { \l__scontents_writing_bool && \l__scontents_overwrite_bool } - { - \file_if_exist:nTF {#1} - { \msg_warning:nnx { scontents } { overwrite-file } {#1} } - { \msg_warning:nnx { scontents } { writing-file } {#1} } - \iow_open:Nn \l__scontents_file_iow {#1} - } - \bool_if:nT { \l__scontents_writing_bool && !\l__scontents_overwrite_bool } + \__scontents_file_if_writable:nTF {#1} { - \file_if_exist:nF {#1} - { \msg_warning:nnx { scontents } { writing-file } {#1} } - \iow_open:Nn \l__scontents_file_iow {#1} + \bool_set_true:N \l__scontents_writable_bool + \iow_open:Nn \l__scontents_file_iow {#1} } + { \bool_set_false:N \l__scontents_writable_bool } \tl_clear:N \l__scontents_file_tl \seq_map_function:NN \l_char_special_seq \char_set_catcode_other:N \int_step_function:nnnN { 128 } { 1 } { 255 } \char_set_catcode_letter:n @@ -452,7 +463,7 @@ } \cs_new_protected:Npn \__scontents_file_write_stop:N #1 { - \bool_if:NT \l__scontents_writing_bool + \bool_if:NT \l__scontents_writable_bool { \iow_close:N \l__scontents_file_iow } \use:x { @@ -483,7 +494,7 @@ \cs_new:Npn \__scontents_remove_leading_nl:w ^^J { } \cs_new_protected:Npn \__scontents_verb_processor_output:n #1 { - \bool_if:NT \l__scontents_writing_bool + \bool_if:NT \l__scontents_writable_bool { \iow_now:Nn \l__scontents_file_iow {#1} } \bool_if:NT \l__scontents_storing_bool { \tl_put_right:Nn \l__scontents_file_tl { ^^J #1 } } @@ -563,19 +574,14 @@ ####2 \exp_not:N \q__scontents_stop } { \__scontents_analyse_nesting_generic_process:nn {##1} {##2} } } -\cs_new_protected:Npn \__scontents_atend_environment: +\cs_new_protected:Npn \__scontents_finish_storing:NNN #1 #2 #3 { \bool_if:NT \l__scontents_storing_bool { \bool_if:NF \l__scontents_forced_eol_bool - { - \tl_put_right:Nx \l__scontents_macro_tmp_tl - { \c__scontents_hidden_space_str } - } - \__scontents_store_to_seq:NN \l__scontents_macro_tmp_tl - \l__scontents_name_seq_env_tl - \bool_if:NT \l__scontents_print_env_bool - { \__scontents_lastfrom_seq:n \l__scontents_name_seq_env_tl } + { \tl_put_right:Nx #1 { \c__scontents_hidden_space_str } } + \__scontents_store_to_seq:NN #1 #2 + \bool_if:NT #3 { \__scontents_lastfrom_seq:V #2 } } } \cs_if_exist:NF \dospecials @@ -583,8 +589,37 @@ \cs_new:Npn \dospecials { \seq_map_function:NN \l_char_special_seq \do } } +\int_new:N \l__scontents_save_sf_int +\dim_new:N \l__scontents_save_skip_dim +\cs_new_protected:Npn \__scontents_bsphack: + { + \scan_stop: + \mode_if_horizontal:T + { + \dim_set_eq:NN \l__scontents_save_skip_dim \tex_lastskip:D + \int_set_eq:NN \l__scontents_save_sf_int \tex_spacefactor:D + } + } +\cs_new_protected:Npn \__scontents_esphack: + { + \scan_stop: + \mode_if_horizontal:T + { + \int_set_eq:NN \tex_spacefactor:D \l__scontents_save_sf_int + \dim_compare:nNnT { \l__scontents_save_skip_dim } > { \c_zero_dim } + { + \dim_compare:nNnT { \tex_lastskip:D } = { \c_zero_dim } + { + \nobreak + \skip_horizontal:n { \c_zero_skip } + } + \tex_ignorespaces:D + } + } + } \cs_new_protected:Npn \__scontents_Scontents_internal:nn #1 #2 { + \__scontents_bsphack: \group_begin: \tl_if_novalue:nF {#2} { \keys_set:nn { scontents / Scontents } {#2} } @@ -595,24 +630,59 @@ } \cs_new_protected:Npn \__scontents_norm_arg:n #1 { - \tl_set:Nx \l__scontents_temp_tl { \exp_not:n {#1} } - \tl_put_right:Nx \l__scontents_temp_tl { \c__scontents_hidden_space_str } - \__scontents_store_to_seq:NN \l__scontents_temp_tl \l__scontents_name_seq_cmd_tl - \bool_if:NT \l__scontents_print_cmd_bool - { \__scontents_lastfrom_seq:n \l__scontents_name_seq_cmd_tl } - \group_end: + \tl_set:Nn \l__scontents_temp_tl {#1} + \__scontents_Scontents_finish: } \cs_new_protected:Npn \__scontents_verb_arg_internal:n #1 { - \tl_set:Nx \l__scontents_temp_tl { \exp_not:n {#1} } + \tl_set:Nn \l__scontents_temp_tl {#1} \tl_replace_all:Nxx \l__scontents_temp_tl { \iow_char:N \^^M } { \iow_char:N \^^J } - \bool_if:NF \l__scontents_forced_eol_bool - { \tl_put_right:Nx \l__scontents_temp_tl { \c__scontents_hidden_space_str } } - \__scontents_store_to_seq:NN \l__scontents_temp_tl \l__scontents_name_seq_cmd_tl - \bool_if:NT \l__scontents_print_cmd_bool - { \__scontents_lastfrom_seq:n \l__scontents_name_seq_cmd_tl } + \__scontents_Scontents_finish: + } +\cs_new_protected:Npn \__scontents_Scontents_finish: + { + \__scontents_file_write_cmd:VV \l__scontents_fname_out_tl \l__scontents_temp_tl + \__scontents_finish_storing:NNN \l__scontents_temp_tl + \l__scontents_name_seq_cmd_tl \l__scontents_print_cmd_bool + \use:x + { \group_end: + \bool_if:NF \l__scontents_print_cmd_bool { \__scontents_esphack: } + } + } +\cs_new_protected:Npn \__scontents_file_write_cmd:nn #1#2 + { + \__scontents_file_if_writable:nT {#1} + { + \iow_open:Nn \l__scontents_file_iow {#1} + \iow_now:Nn \l__scontents_file_iow {#2} + \iow_close:N \l__scontents_file_iow + } + } +\prg_new_protected_conditional:Npnn \__scontents_file_if_writable:n #1 { T, F, TF } + { + \bool_if:NTF \l__scontents_writing_bool + { + \file_if_exist:nTF {#1} + { + \bool_if:NTF \l__scontents_overwrite_bool + { + \msg_warning:nnx { scontents } { overwrite-file } {#1} + \prg_return_true: + } + { + \msg_warning:nnx { scontents } { not-writing } {#1} + \prg_return_false: + } + } + { + \msg_warning:nnx { scontents } { writing-file } {#1} + \prg_return_true: + } + } + { \prg_return_false: } } +\cs_generate_variant:Nn \__scontents_file_write_cmd:nn { VV } \cs_new_protected:Npn \__scontents_getstored_internal:nn #1 #2 { \group_begin: @@ -641,8 +711,8 @@ \__scontents_foreach_add_body:n \tl_gset:Nx \g__scontents_temp_tl { - \seq_use:Nn \l__scontents_foreach_print_seq - { \tl_use:N \l__scontents_foreach_sep_tl } + \exp_args:NNV \seq_use:Nn + \l__scontents_foreach_print_seq \l__scontents_foreach_sep_tl } \group_end: \exp_after:wN \tl_gclear:N @@ -785,6 +855,8 @@ { Overwriting~file~'#1'. } \msg_new:nnn { scontents } { writing-file } { Writing~file~'#1'. } +\msg_new:nnn { scontents } { not-writing } + { File~`#1'~already~exists.~Not~writing. } \msg_new:nnn { scontents } { rescanning-text } { Rescanning~text~'#1'~after~\c_backslash_str end{#2}~\msg_line_context:.} \msg_new:nnn { scontents } { multiple-begin } diff --git a/Master/texmf-dist/tex/generic/scontents/scontents.tex b/Master/texmf-dist/tex/generic/scontents/scontents.tex index 03078a4cc9f..805c0430047 100644 --- a/Master/texmf-dist/tex/generic/scontents/scontents.tex +++ b/Master/texmf-dist/tex/generic/scontents/scontents.tex @@ -6,7 +6,7 @@ %% %% scontents.dtx (with options: `loader,plain') %% -%% Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> +%% Copyright (C) 2019-2020 by Pablo González L <pablgonz@educarchile.cl> %% %% This work may be distributed and/or modified under the conditions of the %% LaTeX Project Public License, either version 1.3c of this license or (at @@ -27,8 +27,8 @@ %% t-scontents.mkiv and %% scontents-code.tex. %% -\def\ScontentsFileDate{2019-11-18}% -\def\ScontentsFileVersion{1.8}% +\def\ScontentsFileDate{2020-01-21}% +\def\ScontentsFileVersion{1.9}% \def\ScontentsFileDescription{Stores LaTeX contents in memory or files}% \input expl3-generic.tex \ExplSyntaxOn |