Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Add SHORT_REPEAT option



SHORT_LOOPS is bad, but repeat 5 echo hi is convenient, so add a separate
option to allow this syntax.

---

Will add docs if nobody objects to this (and not planning to commit this
before 5.8 either way)

 Src/lex.c            |  2 +-
 Src/options.c        |  1 +
 Src/parse.c          |  2 +-
 Src/zsh.h            |  1 +
 Test/E01options.ztst | 19 ++++++++++++++-----
 5 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/Src/lex.c b/Src/lex.c
index f43bcc7db9..2e0dac2d7a 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -270,7 +270,7 @@ zshlex(void)
     do {
 	if (inrepeat_)
 	    ++inrepeat_;
-	if (inrepeat_ == 3 && isset(SHORTLOOPS))
+	if (inrepeat_ == 3 && (isset(SHORTLOOPS) || isset(SHORTREPEAT)))
 	    incmdpos = 1;
 	tok = gettok();
     } while (tok != ENDINPUT && exalias());
diff --git a/Src/options.c b/Src/options.c
index 7c7506cbe2..4421e516ec 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -254,5 +254,6 @@ static struct optname optns[] = {
 {{NULL, "shoptionletters",    OPT_EMULATE|OPT_BOURNE},	 SHOPTIONLETTERS},
 {{NULL, "shortloops",	      OPT_EMULATE|OPT_NONBOURNE},SHORTLOOPS},
+{{NULL, "shortrepeat",	      OPT_EMULATE},              SHORTREPEAT},
 {{NULL, "shwordsplit",	      OPT_EMULATE|OPT_BOURNE},	 SHWORDSPLIT},
 {{NULL, "singlecommand",      OPT_SPECIAL},		 SINGLECOMMAND},
 {{NULL, "singlelinezle",      OPT_KSH},			 SINGLELINEZLE},
diff --git a/Src/parse.c b/Src/parse.c
index 53709ac006..b37f90be9a 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -1559,7 +1559,7 @@ par_repeat(int *cmplx)
 	if (tok != ZEND)
 	    YYERRORV(oecused);
 	zshlex();
-    } else if (unset(SHORTLOOPS)) {
+    } else if (unset(SHORTLOOPS) && unset(SHORTREPEAT)) {
 	YYERRORV(oecused);
     } else
 	par_save_list1(cmplx);
diff --git a/Src/zsh.h b/Src/zsh.h
index 9b69625e5c..400c6992ba 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2490,5 +2490,6 @@ enum {
     SHOPTIONLETTERS,
     SHORTLOOPS,
+    SHORTREPEAT,
     SHWORDSPLIT,
     SINGLECOMMAND,
     SINGLELINEZLE,
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 0f6bb34557..7052af9eb8 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -1101,15 +1101,22 @@ F:Regression test for workers/41811
     eval 'for f (word1 word2) print $f'
     eval 'repeat 3 print nonsense'
   }
-  unsetopt shortloops
-  print option unset
+  unsetopt shortloops shortrepeat
+  print shortloops and shortrepeat unset
+  fn
+  setopt shortrepeat
+  print shortrepeat set
   fn
   setopt shortloops
-  print option set
+  print shortloops set
   fn
 0:SHORT_LOOPS option
->option unset
->option set
+>shortloops and shortrepeat unset
+>shortrepeat set
+>nonsense
+>nonsense
+>nonsense
+>shortloops set
 >foo
 >bar
 >word1
@@ -1119,6 +1126,8 @@ F:Regression test for workers/41811
 >nonsense
 ?(eval):1: parse error near `print'
 ?(eval):1: parse error near `print'
+?(eval):1: parse error near `print'
+?(eval):1: parse error near `print'
 ?(eval):1: parse error near `print'
 
   fn() { print -l $*; }
-- 
2.15.1



Messages sorted by: Reverse Date, Date, Thread, Author