[latex3-commits] [latex3/l3sys-query] 2e: more special character handling (470d4f7)

github at latex-project.org github at latex-project.org
Wed Mar 13 19:58:23 CET 2024


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

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

commit 470d4f7adeb383405018e33f66e7a861020a8737
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Wed Mar 13 18:58:23 2024 +0000

    more special character handling


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

470d4f7adeb383405018e33f66e7a861020a8737
 l3sys-query.sty | 25 ++++++++++++++++++++++---
 test-2e-01.tex  | 24 ++++++++++++++++--------
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/l3sys-query.sty b/l3sys-query.sty
index 04b0ebc..eae2794 100644
--- a/l3sys-query.sty
+++ b/l3sys-query.sty
@@ -24,17 +24,30 @@
   \sys_get_query:nN {pwd} #1
 }
 
+% for saving the current definition of \% and ~
+\tl_new:N\l_query_percent_tl
+\tl_new:N\l_query_tilde_tl
+
+% allow % and ^^ at the top level
 \NewDocumentCommand\QueryFiles {} {
   \group_begin:
-    \char_set_catcode_other:N \~
     \char_set_catcode_other:N \%
+    \char_set_catcode_other:N \^
     \QueryFiles_inner
- }
+  }
+
+\char_set_catcode_active:N \~
 \NewDocumentCommand\QueryFiles_inner {O{}m}{
   \group_end:
   \tl_set:Nn\l_tmpa_tl{}
+  \cs_set_eq:NN  \l_query_percent_tl \%
+  \cs_set_eq:NN  \% \c_percent_str
+  \cs_set_eq:NN  \l_query_tilde_tl ~
+  \cs_set_eq:NN  ~ \c_tilde_str
   \keys_set:nn{QueryFiles}{#1}
   \exp_args:NnV\sys_split_query:nnnN {ls} \l_tmpa_tl {#2} \l_tmpa_seq
+  \cs_set_eq:NN  \% \l_query_percent_tl
+  \cs_set_eq:NN  ~ \l_query_tilde_tl
   \seq_map_inline:Nn\l_tmpa_seq
 }
 
@@ -43,17 +56,23 @@
 
 \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{}
+  \cs_set_eq:NN  \l_query_percent_tl \%
+  \cs_set_eq:NN  \% \c_percent_str
+  \cs_set_eq:NN  \l_query_tilde_tl ~
+  \cs_set_eq:NN  ~ \c_tilde_str
   \keys_set:nn{QueryFiles}{#1}
   \exp_args:NnV\sys_split_query:nnnN {ls} \l_tmpa_tl {#2} \l_tmpa_seq
+  \cs_set_eq:NN  \% \l_query_percent_tl
+  \cs_set_eq:NN  ~ \l_query_tilde_tl
   \seq_if_empty:NTF \l_tmpa_seq \use_iii:nnn \__queryfiles_aux:nnn
 }
+\char_set_catcode_space:N \~
 
 
 \cs_new:Npn  \__queryfiles_aux:nnn #1#2#3 {
diff --git a/test-2e-01.tex b/test-2e-01.tex
index 49a8692..2319ab1 100644
--- a/test-2e-01.tex
+++ b/test-2e-01.tex
@@ -8,25 +8,33 @@
 \typeout{PWD: \thisdir}
 
 
-\QueryFiles{*.tex}{\typeout{A: #1}}
+\QueryFiles{*.tex}{\typeout{star: #1}}
 
-\QueryFiles[recursive,type=d]{}{\typeout{B: #1}}% . ought to work
+\QueryFiles[recursive,type=d]{}{\typeout{recursive d: #1}}
 
-\QueryFiles[type=f]{}{\typeout{C_: #1}}% default
-\QueryFiles[type=f]{*}{\typeout{C*: #1}}% * same as {}
-\QueryFiles[type=f]{.}{\typeout{C.: #1}}% . same as {}
+\QueryFiles[type=f]{}{\typeout{f _: #1}}% default
+\QueryFiles[type=f]{*}{\typeout{f *: #1}}% * same as {}
+\QueryFiles[type=f]{.}{\typeout{f .: #1}}% . same as {}
 
-\QueryFiles[sort=date]{*.tex}{\typeout{D: #1}}
+\QueryFiles[sort=date]{*.tex}{\typeout{date: #1}}
 
-\QueryFiles[pattern]{^[0-9].*.tex}{\typeout{E: #1}}
+\QueryFiles[pattern]{^[0-9].*.tex}{\typeout{pattern: #1}}
 
 
-\QueryFiles[pattern]{^%d.*.tex}{\typeout{F: #1}}
+\QueryFiles[pattern]{^%d.*.tex}{\typeout{percent: #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}}
 
 
+\QueryFiles{[0-9]+.tex}{\typeout{glob bracket: #1}}
+\QueryFiles[pattern]{^[0-9].*tex}{\typeout{pattern bracket: #1}}
+
+\QueryFiles{*^^*.tex}{\typeout{hathat: #1}}
+
+\def\ext{.sty}
+\QueryFiles{*\ext}{\typeout{ext macro: #1}}
+
 \stop
 





More information about the latex3-commits mailing list.