From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 7BA352C8F3 for ; Wed, 13 Mar 2024 05:14:03 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1710303243; b=Mg9EXVf57LE+uGmgV3BUzx9cJBQK04tEfUulVMuuZGZgNl4EZH4TtnqOYpWphIV5kKSqedK+xP DaIvKbIAfwIhDto7F1OWjj14uIkLTPM/8BaUEMyt9fVuSJodxIqnyXYQqL57+bOraShVwLXeV7 /iKEpOuWV0IC2iQFJx7B6S4GVpYoq9p2WJ+HKn0gyGFTNxOJkp5gc/A1OcXyEOKH45Wbyg8UQk 3G4WjY/9R38sGSUFi96mom1PS2zroRgEp0xtI4Uuub3bE0pFk4mhF23OYmdhhJ07bTcGg156dC 7eUTxMPtVpD8jekBtdZ0XR8F8qOsMZlCjLBjdcm7hOEEWA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1710303243; bh=bV5j0WWsBHt+4DyXDFeieCDGN2MGAbkS33/f3mLl+JE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=PYCXwSZepBo75QR6oJ2CjGhWQ+7YvPcWlTFUziFQfL2VjxOKCVq7R5ZwtrSkdCWyJZ7PasUC/1 keweCjLr+qay1sp1zU1jJC48AreohWY7yJ9SRG+uekdJ+BYBCb8u/OpKzpWnaQfbGQpO/2Ylto WTW/X/Yq3/iAQE98Ic5xJkAW6i+dJ86h4reFuYKW/IlWKMXYolFu0slJ8esd/07xRg/tXa8Xt0 iMwUcvQI5HcypndIbZcCL75dlA0159QPs2aIm+Sko0jHqkiAXihE8g0PEnV6qo7cCMQmby/oQE keVrdoTPTEQ+9MPwRm6QFUP4jyF4U9eeefne2pYyiM6AwQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=qsgQ6kLmfPJBp53c+v6vNbAQhcQiBSL1u9zG0AA1aEM=; b=jnZOrZrM5h5GWZH37m3xIySs0n HlhAo4EIwx5KVw6zySkHohH1AIjCRGN0WdHtQXedCHcYCqQXxste4NKp68Cdb++6p7wioYy5RkX0p VjfapaDU9so1VM7hSQp5lbRN8UqRsv5hkWjU22g5r5AihLy7UdLkdLNNVMZinHyIPsTsFoEvwjIhl BzQ11JF96BwMdn0tlHWOgIVUrOPmbLr2tziymJyxpQ7ilPkMB4qU9pfdXl9E/Ph4Uo+p4ZM+BnE9p iwSD53QH1V6tYpwomqnHVU0ekOFskRjBL7bFfSXatAySyKh9CER2wpEgVUO95sZbUcCUc+zZb71Ht iiSeHbsw==; Received: by zero.zsh.org with local id 1rkG0A-0003Nl-Ms; Wed, 13 Mar 2024 04:14:02 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f50.google.com ([209.85.218.50]:60515) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rkFzX-00033Z-IO; Wed, 13 Mar 2024 04:13:24 +0000 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a2f22bfb4e6so920628466b.0 for ; Tue, 12 Mar 2024 21:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1710303203; x=1710908003; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qsgQ6kLmfPJBp53c+v6vNbAQhcQiBSL1u9zG0AA1aEM=; b=03WnDUGhC1lX9BG+BMRWef8JcdxmDZsrgZOnjXtZk7ss3tKI9na/1r0MsmFwJZT3VY bskqEK9DE6uuPz+J2Rg9643FO1u50wZuje1HfHRdioNdnpBLHrOpA0tww9K5QV8MIong iyC+Dl+U7D4cJYzB7PpbmNkInJ3tHdNeU58GAatZ1MqfmNPkaexea5pWzdinID9wIaGn 1yGbvDU+kMJ88dfgja4XC9DWVTb7Ue1o4nctrt1gtzZat01ZuVfZc8ZR/jtCvfrvGQbO XclBDr6v4/yhnRdyUagcSs27A1guz5BbqatD8NZHHjGj1Am0GigHuAi5yVMocBiIQVNm baDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710303203; x=1710908003; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qsgQ6kLmfPJBp53c+v6vNbAQhcQiBSL1u9zG0AA1aEM=; b=EMoJAg9Qb2Hc+VAvHsxDNjBOLUzo+GUJO71P8ciSmeeDfoE4w4IQWpdcwVs4NewMxZ jgVvk0JKje59L8c5F2INBH5BKguR9m3r57rAi3HLGklrrVRIJDtcyR4WxshvCbP8cDA4 Xosdki93seNC7T1KMQhUJWH25qMfTI1Z0HItdc8RUxCLV1Kql2OogwGTCx+3FWcUDRe3 KfYB+jPHHSMoamhiSnJoeBd9u48nm0CINxbmfCAHFE1EGsKqUf53kefC/9oRHeiKAM4N kgBo87J8R6dykbrLBlQuxf5mJhC926fjZ2sA3LzZQGgArqJLRVL9OVUi7zR1Okoiu1ZG gLqw== X-Gm-Message-State: AOJu0Yzx1ohyku8ItExvOWX6MDCEhg7k5wJuN23kPROAcDKHiAa1JMSr hMs2nfd8bPH/IwDZymJyRGQ56zWmUsJlIv9BjttU3jAIo2QzDO4mQeauTXc+KG/6oZ3bN6z1MtJ Igf2dfod97YQ0Eggg5Zj/hphC3/BVaNy1r4kDbXv6PqFycxlCiQ== X-Google-Smtp-Source: AGHT+IGpiAnr2vi+CuXGfIJ9cm1aSfXM62ZX/e5v389v3bZarVlcrh2SxoU6bOfYc0eJ0gW+gnAHURRiqs+hzwWZydo= X-Received: by 2002:a17:907:c70d:b0:a45:c15f:4b37 with SMTP id ty13-20020a170907c70d00b00a45c15f4b37mr3179447ejc.5.1710303202818; Tue, 12 Mar 2024 21:13:22 -0700 (PDT) MIME-Version: 1.0 References: <20240305065606.ccr2ieheahslcpye@chazelas.org> <20240306175711.t3uz2sery3b6tbjw@chazelas.org> <90726-1709936102.086878@xlWC.oGpX.V4Q4> <34739-1710017038.959920@XhYc.enDL.DTxr> <25344-1710285573.990297@5-7t._0Mp.XRXG> In-Reply-To: <25344-1710285573.990297@5-7t._0Mp.XRXG> From: Bart Schaefer Date: Tue, 12 Mar 2024 21:13:09 -0700 Message-ID: Subject: Re: [PATCH?] Nofork and removing newlines To: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52744 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Mar 12, 2024 at 4:19=E2=80=AFPM Oliver Kiddle wrote: > > > Bart Schaefer wrote: > > > See above about the requirement for it to look like ${|ident|...}. > > > Since =3D * and ? are not identifiers, this is like writing { =3D|: }= etc. > > Considering this explanation, it is apparent that allowing |ident| is > not fully compatible with mksh where ${|ls| cat -} runs ls. Hm, yes. Although I wasn't really aiming for compatibility, rather for borrowing the idea (via Sebastian's original attempt at it). I was also I confess a bit stuck on the idea that every case would look like ${|REPLY=3D...} when of course piping to "read" etc. are also valid ways to assign to REPLY. How often would there be a command name with no arguments in that position? > And this leads on to the later question as we probably don't want to > expand considerably on what is valid between the vertical bars. I hesitate in suggesting this, but ... is there any existing case in which "${{" is valid? If not, I think I can change ${|var|...} to be ${{var}...} without too much violence (except to the doc, bleah). > Yes that works. Is nice to see namerefs coming up in nifty solutions. I > hadn't checked the code for what supporting ? / ! would involve. Mostly it involves rejiggering valid_refname() to behave more like itype_end(), if you mean supporting e.g. ${|?|...}. > If trivial why not, but I well understand not wanting to do anything > that involves the lexer. That (and using {var} instead of |var|) would except for a single conditional test all happen in subst.c, the lexer already skips ahead. > Bart Schaefer wrote: > > [...] I could investigate > > whether we could do things like ${|=3D|...} is the same as ${=3D${ ... = }}, > > ${|~|...} is ${~${ ... }}, etc. That only saves 1 character, though, > > and I'm not sure it's clearer. > > Would that potentially also extend to something like ${|=3Dvar| ... } It could, yes. > That might look like a default value assignment to someone Would ${{=3Dvar}...} look better? The doubled braces do give me pause. > Given that the ${|var| ... } form appears to create a function-like > scope, should var perhaps be auto-declared local for that scope and the > local value be substituted? I considered that but (a) the implementation is messy, as the state of the parameter scope has to be carried around subst.c a lot longer than with the single known scalar "REPLY" (b) it diverges even farther from the idea that REPLY is a semi-special thing -- note that REPLY is automatically saved and restored around ${|... REPLY=3D...} (c) creating it local doesn't really add much that you can't do with ${ local value; ... } and (d) part of the point was to be able to push the variable up to the caller as a side effect, so you don't have to write value=3D${|value| ... value=3D...} although I guess you do have to declare it somewhere so that's not entirely helpful. > The quoting approach is clean and logical and is probably my preferred > option. [...] consistency with ${var} is perhaps more > important - it does word splitting based on the shwordsplit option. Thanks for the vote. > > Separately, it's definitely possible to make zsh-mode ${ ... } trim > > only one newline instead of all of them. > > Only one is probably the most useful. I would mostly associate the fact > that $(...) strips multiple with the fact that it does word splitting This is the code diff to make emulation trim all, ${ ... } trim one, "${ ... }" trim none ... not re-doing the doc diff yet. diff --git a/Src/subst.c b/Src/subst.c index 49f7336bb..9d20a2d0e 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1900,6 +1900,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, /* The command string to be run by ${|...;} */ char *cmdarg =3D NULL; size_t slen =3D 0; + int trim =3D (!EMULATION(EMULATE_ZSH)) ? 2 : !qt; inbrace =3D 1; s++; @@ -2005,10 +2006,13 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, int onoerrs =3D noerrs, rplylen; noerrs =3D 2; rplylen =3D zstuff(&cmdarg, rplytmp); - if (! EMULATION(EMULATE_ZSH)) { + if (trim) { /* bash and ksh strip trailing newlines here */ - while (rplylen > 0 && cmdarg[rplylen-1] =3D=3D '\n') + while (rplylen > 0 && cmdarg[rplylen-1] =3D=3D '\n') { rplylen--; + if (trim =3D=3D 1) + break; + } cmdarg[rplylen] =3D 0; } noerrs =3D onoerrs;