zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH?] Nofork and removing newlines
Date: Thu, 7 Mar 2024 16:37:07 -0800	[thread overview]
Message-ID: <CAH+w=7aTyJMxCJJQpKJxR-C=tauQm6=dPA0DMXsy7hi6+HX_PQ@mail.gmail.com> (raw)
In-Reply-To: <20240307071016.sk66axbt5n4cqv6c@chazelas.org>

On Wed, Mar 6, 2024 at 11:10 PM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> For ${=${ foo }} that depends on whether $IFS contains a
> (non-doubled) newline or not.

True, but I think not really relevant, because nobody is (I hope)
going to globally set a strange IFS in their dotfiles and still expect
any normal behavior.

> For (f), see also:
>
> $ printf '<%s>\n' "${(f@)${ print -l 'a b' '' 'c d' }}"
> <a b>
> <>
> <c d>
> <>

That's because of the historic behavior of the (s::) flag where (f) is
(ps:\n:).  But as was pointed out elsewhere if you're not invoking an
external command you can control this from inside the substitution:

% printf '<%s>\n' "${(f@)${ print -nl 'a b' '' 'c d' }}"
<a b>
<>
<c d>
%

Which leans a little in the direction of never trimming rather than of
choosing how many to trim.

It does however reveal a drawback in the quoting proposal, in that
when nesting ${ ... } inside another quoted expansion there would be
no way to disable newline retention.

> We'd need to have a way to treat the separator as *delimiter*

That would be a useful choice for (T) or some other new flag -- as in,
do NOT "trim" the separator when splitting -- but I don't see how it
helps decide whether to trim trailing newline(s) from ${ cmd } in the
first place, because in the delimiter case you'd want to keep them?

Just for grins ...

% : ${|reply|
  typeset -ga reply
  local -i i=1 MBEGIN MEND
  local -n MATCH='reply[i]'
  local pat=$'[^\n]#\n'
  : ${(*S)"${ print -l 'a b' '' 'c d' }"//(#m)($~pat)/$((i++))}
}
% typeset -p reply
typeset -a reply=( $'a b\n' $'\n' $'c d\n' )


  reply	other threads:[~2024-03-08  0:37 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  5:52 Bart Schaefer
2024-03-05  6:56 ` Stephane Chazelas
2024-03-05 22:48   ` Bart Schaefer
2024-03-06 17:57     ` Stephane Chazelas
2024-03-06 19:45       ` Bart Schaefer
2024-03-06 22:22         ` Mikael Magnusson
2024-03-06 22:42           ` Bart Schaefer
2024-03-07  4:53           ` Bart Schaefer
2024-03-07  7:02             ` Lawrence Velázquez
2024-03-07  8:09               ` ${<file} (Was: [PATCH?] Nofork and removing newlines) Stephane Chazelas
2024-03-08  1:29               ` [PATCH?] Nofork and removing newlines Bart Schaefer
2024-03-08 22:15                 ` Oliver Kiddle
2024-03-08 23:28                   ` Bart Schaefer
2024-03-09 20:43                     ` Oliver Kiddle
2024-03-10  6:11                       ` Bart Schaefer
2024-03-12 17:54                         ` Bart Schaefer
2024-03-12 23:19                           ` Oliver Kiddle
2024-03-13  4:13                             ` Bart Schaefer
2024-03-14 22:15                               ` Oliver Kiddle
2024-03-15  8:42                                 ` Stephane Chazelas
2024-03-27  1:16                                   ` Bart Schaefer
2024-03-27  7:05                                 ` Bart Schaefer
2024-03-07  7:10             ` Stephane Chazelas
2024-03-08  0:37               ` Bart Schaefer [this message]
2024-03-07  6:52           ` Lawrence Velázquez
2024-03-07  8:26             ` Mikael Magnusson
2024-03-07 19:02               ` Bart Schaefer
2024-04-02  6:45                 ` Lawrence Velázquez
2024-03-06 19:43     ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7aTyJMxCJJQpKJxR-C=tauQm6=dPA0DMXsy7hi6+HX_PQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).