[latex3-commits] [latex3/l3sys-query] 2e: add version with empty seq test @FrankMittelbach (56bfc4c)

github at latex-project.org github at latex-project.org
Sun Mar 10 12:36:12 CET 2024


Repository : https://github.com/latex3/l3sys-query
On branch  : 2e
Link       : https://github.com/latex3/l3sys-query/commit/56bfc4c8f64c120918a013d9bc80979a8674c8f8

>---------------------------------------------------------------

commit 56bfc4c8f64c120918a013d9bc80979a8674c8f8
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Sun Mar 10 11:36:12 2024 +0000

    add version with empty seq test  @FrankMittelbach


>---------------------------------------------------------------

56bfc4c8f64c120918a013d9bc80979a8674c8f8
 l3sys-query.sty | 31 ++++++++++++++++++++++++++++---
 test-2e-01.tex  |  8 +++++++-
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/l3sys-query.sty b/l3sys-query.sty
index 050a691..1c02d9a 100644
--- a/l3sys-query.sty
+++ b/l3sys-query.sty
@@ -10,10 +10,13 @@
 % defines the command passed in as #1 to be the current working directory
 
 % \QueryFiles[<options>]{<args>}{function}
+% \QueryFilesTF[<options>]{<args>}{function}{<Pre list code>}{<empty list code>}
 % produces a file list based on args and the options then applies function to each one.
 % function should be a macro body which will be passed the file path as  #1
 % on each iteration.
 % For options and details see l3sys.dtx
+% The TF version executes the T (<Pre list code>) argument before iterating over the list
+% and the F (<empty list code>) argument if the list is empty
 
 \ExplSyntaxOn
 
@@ -21,21 +24,43 @@
   \sys_get_query:nnnN {pwd} {} {} #1
 }
 
-
 \NewDocumentCommand\QueryFiles {} {
   \group_begin:
     \char_set_catcode_other:N \~
     \char_set_catcode_other:N \%
     \QueryFiles_inner
  }
-\NewDocumentCommand\QueryFiles_inner {O{}mm}{
+\NewDocumentCommand\QueryFiles_inner {O{}m}{
   \group_end:
   \tl_set:Nn\l_tmpa_tl{}
   \keys_set:nn{QueryFiles}{#1}
   \exp_args:NnV\sys_split_query:nnnN {ls} \l_tmpa_tl {#2} \l_tmpa_seq
-  \seq_map_inline:Nn\l_tmpa_seq{#3}
+  \seq_map_inline:Nn\l_tmpa_seq
 }
 
+% duplicates rather than shares code so as to read the function and TF arguments
+% with normal catcode regime. (This could probably be optimised)
+
+\NewDocumentCommand\QueryFilesTF {} {
+  \group_begin:
+    \char_set_catcode_other:N \~
+    \char_set_catcode_other:N \%
+    \QueryFilesTF_inner
+ }
+\NewDocumentCommand\QueryFilesTF_inner {O{}m}{
+  \group_end:
+  \tl_set:Nn\l_tmpa_tl{}
+  \keys_set:nn{QueryFiles}{#1}
+  \exp_args:NnV\sys_split_query:nnnN {ls} \l_tmpa_tl {#2} \l_tmpa_seq
+  \seq_if_empty:NTF \l_tmpa_seq \use_iii:nnn \__queryfiles_aux:nnn
+}
+
+
+\cs_new:Npn  \__queryfiles_aux:nnn #1#2#3 {
+    #2
+    \seq_map_inline:Nn\l_tmpa_seq {#1}
+ }
+
 \keys_define:nn {QueryFiles} {
 recursive .code:n  =\tl_put_right:Nn \l_tmpa_tl {--recursive ~ } ,
 recursive .value_forbidden:n = true ,
diff --git a/test-2e-01.tex b/test-2e-01.tex
index c457bec..5c00dcd 100644
--- a/test-2e-01.tex
+++ b/test-2e-01.tex
@@ -1,7 +1,8 @@
 \documentclass{article}
 \usepackage{l3sys-query}
 
-\errorcontextlines888
+
+
 \QueryPWD \thisdir
 
 \typeout{PWD: \thisdir}
@@ -18,5 +19,10 @@
 
 \QueryFiles[pattern]{^%d.*.tex}{\typeout{E: #1}}
 
+\QueryFilesTF{t*.*}{\typeout{TFA: #1}}{\typeout{TFA files:}}{\typeout{TFA empty file list}}
+
+\QueryFilesTF{wibble*.*}{\typeout{TFB: #1}}{\typeout{TFB files:}}{\typeout{TFB empty file list}}
+
+
 \stop
 





More information about the latex3-commits mailing list.