[latex3-commits] [git/LaTeX3-latex3-latex3] master: Simplify code by limiting use of \use:x when setting up definitions (7942d35)

Bruno Le Floch bruno at le-floch.fr
Sat Apr 7 06:51:11 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/7942d353c76f0d5c8e6fce5db751dca857ddc3d3

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

commit 7942d353c76f0d5c8e6fce5db751dca857ddc3d3
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sat Apr 7 00:51:11 2018 -0400

    Simplify code by limiting use of \use:x when setting up definitions
    
    It is often simpler to use finer expansion control, specifically the
    surprisingly useful \exp_last_unbraced:NNNNo.


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

7942d353c76f0d5c8e6fce5db751dca857ddc3d3
 l3kernel/l3basics.dtx |   27 +++++++++++++--------------
 l3kernel/l3expan.dtx  |    9 +++------
 l3kernel/l3file.dtx   |   21 +++++++++------------
 l3kernel/l3fp-aux.dtx |    9 +++------
 l3kernel/l3keys.dtx   |    9 +++------
 l3kernel/l3str.dtx    |    4 ++--
 l3kernel/l3tl.dtx     |   21 +++++++++------------
 7 files changed, 42 insertions(+), 58 deletions(-)

diff --git a/l3kernel/l3basics.dtx b/l3kernel/l3basics.dtx
index 9a984e4..d3c2227 100644
--- a/l3kernel/l3basics.dtx
+++ b/l3kernel/l3basics.dtx
@@ -2557,22 +2557,21 @@
 %   auxiliary trims the trailing \cs{q_mark} from the function name if
 %   present (that is, if the original function had no colon).
 %    \begin{macrocode}
-\cs_set:Npx \@@_split_function:NN #1
+\cs_set_protected:Npn \@@_tmp:w #1
   {
-    \exp_not:N \exp_after:wN \exp_not:N \exp_after:wN
-    \exp_not:N \exp_after:wN \exp_not:N \@@_split_function_auxi:w
-      \exp_not:N \cs_to_str:N #1 \exp_not:N \q_mark \c_true_bool
-      \token_to_str:N : \exp_not:N \q_mark \c_false_bool
-      \exp_not:N \q_stop
-  }
-\use:x
-  {
-    \cs_set:Npn \exp_not:N \@@_split_function_auxi:w
-      ##1 \token_to_str:N : ##2 \exp_not:N \q_mark ##3##4 \exp_not:N \q_stop ##5
+    \cs_set:Npn \@@_split_function:NN ##1
+      {
+        \exp_after:wN \exp_after:wN \exp_after:wN \@@_split_function_auxi:w
+          \cs_to_str:N ##1 \q_mark \c_true_bool
+          #1 \q_mark \c_false_bool \q_stop
+      }
+    \cs_set:Npn \@@_split_function_auxi:w
+        ##1 #1 ##2 \q_mark ##3##4 \q_stop ##5
+      { \@@_split_function_auxii:w ##5 ##1 \q_mark \q_stop {##2} ##3 }
+    \cs_set:Npn \@@_split_function_auxii:w ##1##2 \q_mark ##3 \q_stop
+      { ##1 {##2} }
   }
-  { \@@_split_function_auxii:w #5 #1 \q_mark \q_stop {#2} #3 }
-\cs_set:Npn \@@_split_function_auxii:w #1#2 \q_mark #3 \q_stop
-  { #1 {#2} }
+\exp_after:wN \@@_tmp:w \token_to_str:N :
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
diff --git a/l3kernel/l3expan.dtx b/l3kernel/l3expan.dtx
index d788981..cdd35b6 100644
--- a/l3kernel/l3expan.dtx
+++ b/l3kernel/l3expan.dtx
@@ -1969,12 +1969,9 @@
           { : \exp_not:N \use_i:nn }
       }
   }
-\use:x
-  {
-    \cs_new_protected:Npn \exp_not:N \@@_generate_internal_variant:wwnNwnn
-        ##1 \token_to_str:N x ##2 \exp_not:N \q_mark
-        ##3 ##4 ##5 \exp_not:N \q_stop ##6 ##7
-  }
+\exp_last_unbraced:NNNNo
+  \cs_new_protected:Npn \@@_generate_internal_variant:wwnNwnn #1
+    { \token_to_str:N x } #2 \q_mark #3#4#5 \q_stop #6#7
   {
     #3
     \cs_if_free:cT {#6} { #4 {#6} {#7} }
diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index 73a5aba..68b479d 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -928,16 +928,16 @@
 %
 % \begin{macro}{\ior_str_get:NN}
 %   Reading as strings is a more complicated wrapper, as we wish to
-%   remove the endline character.
+%   remove the endline character and restore it afterwards.
 %    \begin{macrocode}
 \cs_new_protected:Npn \ior_str_get:NN #1#2
   {
-    \use:x
+    \exp_args:Nno \use:n
       {
         \int_set:Nn \tex_endlinechar:D { -1 }
-        \exp_not:n { \etex_readline:D #1 to #2 }
-        \int_set:Nn \tex_endlinechar:D { \int_use:N \tex_endlinechar:D }
-      }
+        \etex_readline:D #1 to #2
+        \int_set:Nn \tex_endlinechar:D
+      }   { \int_use:N \tex_endlinechar:D }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1853,13 +1853,10 @@
 % \begin{macro}[EXP]{\@@_wrap_trim:N, \@@_wrap_trim:w}
 %   Remove one trailing \enquote{other} space from the argument.
 %    \begin{macrocode}
-\cs_set_protected:Npn \@@_tmp:w #1
-  {
-    \cs_new:Npn \@@_wrap_trim:N ##1
-      { \tl_if_empty:NF ##1 { \exp_after:wN \@@_wrap_trim:w ##1 \q_stop } }
-    \cs_new:Npn \@@_wrap_trim:w ##1 #1 \q_stop {##1}
-  }
-\exp_args:NV \@@_tmp:w \c_catcode_other_space_tl
+\cs_new:Npn \@@_wrap_trim:N #1
+  { \tl_if_empty:NF #1 { \exp_after:wN \@@_wrap_trim:w #1 \q_stop } }
+\exp_last_unbraced:NNNNo
+  \cs_new:Npn \@@_wrap_trim:w #1 \c_catcode_other_space_tl \q_stop {#1}
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3fp-aux.dtx b/l3kernel/l3fp-aux.dtx
index c2775c6..9c12d8a 100644
--- a/l3kernel/l3fp-aux.dtx
+++ b/l3kernel/l3fp-aux.dtx
@@ -571,12 +571,9 @@
     \exp_not:N \token_to_str:N #1 \exp_not:N \q_mark
       \tl_to_str:n { s_@@ _? } \exp_not:N \q_mark \exp_not:N \q_stop
   }
-\use:x
-  {
-    \cs_new:Npn \exp_not:N \@@_type_from_scan:w
-      ##1 \tl_to_str:n { s_@@ } ##2 \exp_not:N \q_mark ##3 \exp_not:N \q_stop
-      {##2}
-  }
+\exp_last_unbraced:NNNNo
+  \cs_new:Npn \@@_type_from_scan:w #1
+    { \tl_to_str:n { s_@@ } } #2 \q_mark #3 \q_stop {#2}
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 9bac8be..c5c5278 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -1375,12 +1375,9 @@
       }
       { \use:c { \c_@@_props_root_tl \l_@@_property_tl } {#1} }
   }
-\use:x
-  {
-    \cs_new:Npn \exp_not:N \__keys_define_code:w
-      ##1 \c_colon_str ##2 \exp_not:N \q_stop
-  }
-  { \tl_if_empty:nTF {#2} }
+\exp_last_unbraced:NNNNo
+  \cs_new:Npn \__keys_define_code:w #1 \c_colon_str #2 \q_stop
+    { \tl_if_empty:nTF {#2} }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
diff --git a/l3kernel/l3str.dtx b/l3kernel/l3str.dtx
index 22076e9..c4592d7 100644
--- a/l3kernel/l3str.dtx
+++ b/l3kernel/l3str.dtx
@@ -1829,8 +1829,8 @@
       { \@@_change_case_char:nN }
     {#1} #2 \q_recursion_stop
   }
-\use:x
-  { \cs_new:Npn \exp_not:N \@@_change_case_space:n ##1 \c_space_tl }
+\exp_last_unbraced:NNNNo
+  \cs_new:Npn \@@_change_case_space:n #1 \c_space_tl
   {
     \@@_change_case_output:nw { ~ }
     \@@_change_case_loop:nw {#1}
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 5112269..160bca0 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -2061,23 +2061,20 @@
 %   up to be expandable and to check the value exactly.  The question
 %   mark prevents the auxiliary from losing braces.
 %    \begin{macrocode}
-\use:x
+\cs_set_protected:Npn \@@_tmp:w #1
   {
-    \prg_new_conditional:Npnn \exp_not:N \tl_if_novalue:n ##1
+    \prg_new_conditional:Npnn \tl_if_novalue:n ##1
       { p , T ,  F , TF }
       {
-        \exp_not:N \str_if_eq:onTF
-          {
-            \exp_not:N \@@_if_novalue:w ? ##1 { }
-              \c_novalue_tl
-          }
-          { ? { } \c_novalue_tl }
-          { \exp_not:N \prg_return_true: }
-          { \exp_not:N \prg_return_false: }
+        \str_if_eq:onTF
+          { \@@_if_novalue:w ? ##1 { } #1 }
+          { ? { } #1 }
+          { \prg_return_true: }
+          { \prg_return_false: }
       }
-    \cs_new:Npn \exp_not:N \@@_if_novalue:w ##1 \c_novalue_tl
-      {##1}
+    \cs_new:Npn \@@_if_novalue:w ##1 #1 {##1}
   }
+\exp_args:No \@@_tmp:w { \c_novalue_tl }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}





More information about the latex3-commits mailing list