From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 35b8bf13 for ; Thu, 26 Dec 2019 03:00:18 +0000 (UTC) Received: (qmail 2839 invoked by alias); 26 Dec 2019 03:00:08 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45142 Received: (qmail 16739 invoked by uid 1010); 26 Dec 2019 03:00:08 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf1-f51.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25670. spamassassin: 3.4.2. Clear:RC:0(209.85.167.51):SA:0(-2.0/5.0):. Processed in 4.306255 secs); 26 Dec 2019 03:00:08 -0000 X-Envelope-From: mikachu@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.51 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Qj0LPwCLUOpE8cUnC8Q+STBF24diqP7bjyKr71NTV0o=; b=lcpHQ3krcTAsndrwGa8FQ//UlZ5WXOdf7KnFnxUBsq6NWvl1v8DY1Hxb4kDEowDfyf DBx68H95vbuRyxzug9vEl5Q5F8YtDAdAitAY0kDMfr1/Vn8bEwG+xPSdlLB88ezqwy9l DanlgsRGdronGwGY92zqxctxDtwAudHPHtKwhwzXMMg1qxxUKDp5NOOuMO+wJTgab4yi QvdO5uRWL53nK8Zml9hBKHdfFbYdfk2iaVFn56vU/Qz2gNDpZgClRvCzkfP52W/HCgAR SsYIlcGiRBciJnr/nRQiDDh2VgqKE8SttYGfCwdoZi3CyucUcunDQh+st3wio3VvtxO+ FMzw== X-Gm-Message-State: APjAAAXE8YZTU794f5RVs0Zt2sn300o70l1byVyCzMEcwi2L8iJ2DR3S 6hUotkNvEg+82jmM6t4GSKFuoixDGwg= X-Google-Smtp-Source: APXvYqzOp0voR21hD82GNYtq6LHrqE6/aLcY6ReFoFkdMuwtu5UoeqNjoP3zMuJIX2vN3pFW3Dir1g== X-Received: by 2002:ac2:59dd:: with SMTP id x29mr23744079lfn.95.1577329167586; Wed, 25 Dec 2019 18:59:27 -0800 (PST) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Add SHORT_REPEAT option Date: Thu, 26 Dec 2019 03:59:20 +0100 Message-Id: <20191226025920.14498-1-mikachu@gmail.com> X-Mailer: git-send-email 2.15.1 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