From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10498 invoked from network); 15 Aug 2021 01:22:17 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Aug 2021 01:22:17 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1628990537; b=h7TuyW3WuZ1jftE7BDDCtgIjJbss5bEeHN85k9cVzeQu+jKWjCJ+FK20leb386FjCR1jIaxMSK 4CrDggH6yFI2QF72og54FWWEGPYf5HxaTjmqeU7aHKNgxVJbW5NDH1mbTqsHXHtH93sOHurpzB SxV+FBvqLI27XA3Q7IShUICDCCuz2QbiK2ps/4k6SmcJwPxW5qOPfZH14OvewPyvVit9uKFx5D A9NnQ71sZcvb92fUdy2r/ZDKJ47jY04JFWIV7QG+j51hK7w7HA5Cx810AhJy0cQtDd+UHAIF8r jrNs0RusslpMS+c3RVjTU3HSDy7iVosBYR/VdcLJlcaM1g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f177.google.com) smtp.remote-ip=209.85.219.177; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 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=1628990537; bh=i/7vghpclfNneSgsm6AdBkBTcQO3EX28Z0rdUJvcfM4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=QFl394uevkIS7LFisq8vVaJl86Rq27JIfaDyQXfCJAN5kivuBhBSRGd5KTYRxqWzO+uRJVId1t gmIZHD2m6cUcxUfJJ5cF/7gH97mH8+OCfX+EAUVkwRwAfRy6RwpHxDA67HtR02M/eiSyYj+vVL sU64f7J1N29kJOiSRb78/9OoOQO6iKUMDifR9LS0fZHGpaUUk70IMReV7rJ++cuJVzwi5YD9zQ cGnfqj+bhTKNGCt6use2ky9hc+mh6jSa6CGuNbmxFj+7GDxhGUxsq5aKG3pJwZ2Z322ZtmeA5A Q3rhTx00bC65MwrK4GbFwvvPK3j4j7FNIVlGcIH8SU1RfA==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=lAUx0JG7mCUZ9YFzWIMbciDVS8mRpYRS+A8tYMZSu5A=; b=ShfJTZ6C4CKqPRqXsJAv7TQbD4 HqiK6uV2ND6XKGzbNLkfEZqiV5K2gAoFZZU40IzeEIRAFYocurjUN1a2QMm/WnJEdEe2bJt0rc1R1 fanIP///qy9+hUNC6nk4yCPo/OjVRtVXsto6NQMxEKxN5jR92/aydvCQYAM324mD7G1Gg+bgi5+xK 2xRKPRObuA3rVmQE42Lv78VbMoonoY81i/pmE2ic4MigKuPMGE/XEr+43f/LvP29rzO5Zxvfc1Ade UMqmpJgFw4/omWQ0EsoOtBpkaUZ99M7jSpj7sDg/7DZbyhuwT1rUDq+1dnc4u7Qqdsxg5Af88nC+2 AJC4FAqg==; Received: from authenticated user by zero.zsh.org with local id 1mF4qu-0002rA-2A; Sun, 15 Aug 2021 01:22:16 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f177.google.com) smtp.remote-ip=209.85.219.177; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f177.google.com ([209.85.219.177]:43914) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mF4qM-0002Xz-17; Sun, 15 Aug 2021 01:21:43 +0000 Received: by mail-yb1-f177.google.com with SMTP id z128so26016709ybc.10 for ; Sat, 14 Aug 2021 18:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lAUx0JG7mCUZ9YFzWIMbciDVS8mRpYRS+A8tYMZSu5A=; b=HLVOlYj3YfdNT5Tdlv9rm4ftqAqnU3soox+eG2nzEVbp107RL9ygGLuAJwhNGX7TCM UMPj7snaPDdvfhxoHglSLDYcMw6cWZps65c4CNECIFzdfDo0TZqapk3UxiP4wtvr3L1d 9VAr4PJiaUj1pM+oNjbjDJdfEV/A+7IGyy3rlnlW7wM3SY8jUfZoxrjOitxwTexkrqvi es1it8Wf3jDCslg923tQbSKiTKWGFWYV4szmqfOgHC40Vz6lwz+ZjHNkx6btBjqdYFA8 V+H/G+ljyKEMWhfmk9pHSC1yQIzdOQwyNSvDfF6dNenLsNrCN2ZC5Lpv23oWg7ShBIOQ lV1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lAUx0JG7mCUZ9YFzWIMbciDVS8mRpYRS+A8tYMZSu5A=; b=iDfFubvpAJaZUwLJNlz7UCeNNtKYvbsLotihiIFekVir9/+2CIZa89ihuezAsY/Wi0 ljto2Ew75E3whvIVKJKmgOT2H29uXQjh74xsysaAamf2pfqv1tH0l0tPMEFXSkTIC+RR 6ML6mjc5rnXXkBFdVNcUOQmzIN3d/T2n9Iw/9R+cyfEaLWibW2IhZeFX2vdKkthrwn4L j2PhgGqQikeMH8snviFcklaxR/J2XPXm4xMmDB2Cs+Wrm6TzIR5/uLxgXM8hoZWr5oxx /aRDhXUcPKdG5xz9k4fj+mk6WTqy5j66+8/OjggNjo3I5W6M1t4xqgHTwJ8IP4Elon4n t0XA== X-Gm-Message-State: AOAM530v/dAszk95nCfAP6NmN51U6oPw52hegG/Nt8bPLnvoZi+c/Kja AJ7YdJvI1dCM+uCC2i8DQstIActPbZw11YlnyziiN8vD/K8= X-Google-Smtp-Source: ABdhPJxyY8mOYuM5H8rwWMoPo/if7r6AqAwtzXPC6tN6vXsrOtI6rObnlbrg7VZMSqOEtFw7N55968gDSPYzE4i0A3o= X-Received: by 2002:a25:e042:: with SMTP id x63mr12386453ybg.398.1628990500634; Sat, 14 Aug 2021 18:21:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sat, 14 Aug 2021 18:21:29 -0700 Message-ID: Subject: [PATCH] Re: chpwd, precmd hooks have "zsh" in $0 To: Roman Neuhauser Cc: Zsh hackers list Content-Type: multipart/mixed; boundary="000000000000225b0c05c98ee82c" X-Seq: 49282 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: --000000000000225b0c05c98ee82c Content-Type: text/plain; charset="UTF-8" Moving discussion to zsh-workers. On Wed, Aug 11, 2021 at 9:40 PM Roman Neuhauser wrote: > > # schaefer@brasslantern.com / 2021-08-10 10:31:00 -0700: > > > > Theoretically, a function might prefer to know that it was being > > called as a consequence of being found in a given hook list, vs. being > > called directly. That might argue for [calling all with the hookname]. > > yes, but there's other ways to let a function know it's being called as > part of a particular hook array. there's only one reasonable way > of letting a function know the name it was called with. Attached patch implements calling hook functions with $0 as their own name, even in the hook arrays. If there's a better way to nondestructively copy the tail of a LinkList, please tell me. In order to do this for functions that already get an argument list (preexec and zshaddhistory, for example) I had to modify callhookfunc(), so I did NOT change doshfunc(), which means the behavior of zftp callbacks is unchanged and will have to be addressed separately. > > > function a b { ... } > ab.log > > > precmd_functions=(a) > > > preexec_functions=(b) > > > > > > calls the function with $0 == "a" in precmd, "b" in preexec, > > > and that their runtime output goes to ab.log. hooks do neither > > > and TRAPNAL functions only [use ...] > [...] the correct name for a function defined with multiple names. So I dug a little further into why this happens (that is, why redirection does NOT) and found that it's because doshfunc() extracts the function body and jumps directly to the first command in the body via runshfunc(), thereby skipping the redirections, which are normally handled by execcmd_exec() after the function object is looked up there. I haven't verified it, but I believe this also means that "sticky" emulations are not honored by functions called as hooks (and various other entry points that call doshfunc() directly). There's a chicken-and-egg problem here because execcmd_exec() itself eventually runs shell functions by calling execshfunc() which then calls doshfunc(), so we can't push the redirection handling down into doshfunc() ... the order of events for forks and subshells would become wrong. One obvious way to fix this -- and I vaguely recall this having been suggested during the discussion back in 2014 -- is to dispose of the Eprog redir from struct shfunc and instead change the parser to push the redirections onto the Eprog funcdef -- in effect, convert at parse time func() { ... } > file into function func { { ... } > file } What the equivalent is for sticky emulations, I don't know. Another way to fix it might be to change the call signature of doshfunc() to include a flag that says whether to process redirections [and sticky emulations] and then copy code from execmd_exec() that would be run when that flag is true. I'm not sure what the consequences are in terms of correctly unwinding state in those cases. --000000000000225b0c05c98ee82c Content-Type: text/plain; charset="US-ASCII"; name="callhookfunc_arg0.txt" Content-Disposition: attachment; filename="callhookfunc_arg0.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kscidv6h0 ZGlmZiAtLWdpdCBhL1NyYy91dGlscy5jIGIvU3JjL3V0aWxzLmMKaW5kZXggNWE5MjIyOTE5Li5j MzI3NDFjYTcgMTAwNjQ0Ci0tLSBhL1NyYy91dGlscy5jCisrKyBiL1N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