Re: [PATCH v6] regexp-replace and ^, word boundary or look-behind operators (and more).
Mikael Magnusson <[email protected]> Wed, 10 Jun 2026 05:13:41 +0200
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAHYJk3RMQk77fDknU3enurS-3NEB-s+B+V_RrwLhNRhAvE-4fg@mail.gmail.com> |
On Sun, Jun 7, 2026 at 3:16 PM Stephane Chazelas <[email protected]> wrote: > > 2026-06-07 12:36:53 +0200, Mikael Magnusson: > [...] > > setopt functionargzero does not take effect when we have already entered the > > function, so use $funcstack[1] instead. > [...] > > Thanks. I have to admit I'm a bit baffled as to how I ended up > adding that (and that I would have thought about the case where > functionargzero is unset in the first place). > > Probably by testing in other emulation modes. > > If $0 == functionname is not restored by emulate -L zsh, that > would suggest we'd need to replace $0 with $funcstack[1] in all > functions we expect to work whatever the user's set of options. > > I see $funcstack doesn't work when zsh is *started* in sh/ksh/csh > emulation, but I wouldn't expect those instances to use > autoloaded functions anyway. Hmm, right, you'd have to do zmodload -F zsh/parameter p:funcstack (this does take effect immediately, because the variable it reads is maintained always by exec.c). Now that I've looked around in the code, I see that we do indeed use $0 in a lot of places already. Maybe it's better to just leave this as $0 too and leave that particular problem to another cleanup. (It's weird how difficult it is to just consistently get the name of the currently executing function.) Maybe a reasonable compromise is just ${funcstack[1]:-$0} or so (but of course, functionargzero is off in ksh emulation so that'll still say ksh.) The absolutely simplest solution is to just replace all instances of $0 with the name of the file :). Argh, if you're in ksh emulation it's funcstack[0]. You just can't win. TL;DR I'll just leave it as $0 but remove the setopt. -- Mikael Magnusson