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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17107 invoked from network); 5 May 2021 06:11:55 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 May 2021 06:11:55 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1620195115; b=Jg8HTN6uUasgyjpbdVgS3g4CNCcsi3DAXI3Rq+Bnw+DC2EezfAjZOFpkKIqzZdhRuskpg6vQ71 fSK6cXuu+imyXVYaqnuZjOm2XwfiniONPmJTG+7vSpcQqd2qwA8u/7muR1NDEEgpsU8MQS+0LB D4ckYh2eF71ZDzT9qvlLD8bJnmyTzkFv4aM6ieJVQ5J4liphtLL6mkplocWV7qQcz5vLY3v/bM 0nCXpzFYd9QEwjkiNsOMjssojZEwsLyjyaJE9n/i0GGWfyNnCLlGveyT+UfYpfMyYJ+1Lcu1LU tb0IMmKpM11mhCTyjTrLudomgk/B2HD3Mb2VBFLVoKsVkA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f44.google.com) smtp.remote-ip=209.85.167.44; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1620195115; bh=UZ67eIvMUWucTQq2AdfGcbhFhyuAzUolfSzXpBDadCw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=WPLO1BzB9v6HYR0OUEFWNPDCSBHsjJXqdfzvnjySLBc3ogIUsNfYqkCdZVuVTE/wHSQcwT3pgy GUCIV8GUeoaUK00YiQl0pCERKnfHDAY6Syvo2Nr4qiQsdmoyqAL/NDHqUtfBHiTvyMQqMmefRd xa3bFNDbc2H5H6ELyh4/0rTNpXIoJUiWXNa4kUUTaRpH4cSnaSodI3fL0EzOiPdHXe4zXo0uxP mBPwIL+ux5iuif/z7Ys3KxxOK+mxob45Ymr1NQo5LQ9dcMxm4nTNvxVYeHTwVToMXo+peDdn0s F4XuIc0cCGeDmj1eOhRvPvV/2061FvTC7+ICIHMaswEm4g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=JNrbJ6uTS5dcaUEagdgV87VPF6KOZJCZNzugA913jsM=; b=Uy4Lefor74F0eKoeL12VxAoitw /Ndzm8mOTgeUCLbGy6QNV9kWYSwIN4KipBy1hqqA76GDy5/Flun2aL1qzUtA0IOCEe+lJlszqpyOi a2P7keNRzpsdFwZXCfSQerudfTDuyRVE1eTfjesd8AJY4Iu7lBVk0it2MrW3SEDkEQS3tIB0l9E+C gad51jg6QegdlLsgr8w7gsd8dbJXWx633qEJ/Zy3JBQvg3zizJuZpdJU7ELXLEg4V8s5yut2SgG36 T6ggWRgGG1rEPvC4PPuCQDbXYmyUsyyBonlRSS1wenJOlmLagsAWaJSgAgGHEv0Ujh0jrrQqcc5VN Sk7e1tQQ==; Received: from authenticated user by zero.zsh.org with local id 1leAlG-000MsV-Gc; Wed, 05 May 2021 06:11:54 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f44.google.com) smtp.remote-ip=209.85.167.44; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f44.google.com ([209.85.167.44]:42668) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1leAkp-000MRt-99; Wed, 05 May 2021 06:11:29 +0000 Received: by mail-lf1-f44.google.com with SMTP id c11so917360lfi.9 for ; Tue, 04 May 2021 23:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=JNrbJ6uTS5dcaUEagdgV87VPF6KOZJCZNzugA913jsM=; b=LPXEl3jsEIAig3Ppdl7wMLT8KVPoYhmo3hWu2xl14yGIi/0iX8wJe+J29X/vS2+1T0 1il9NpI0e6PUI22k48sH5/W8UpTRwUoMn4lcOqMnnJ7qu36fd9IMYqW+5WUhbt/YjUrQ DspoiscRI+JiWNGJ7L/CUPvfF4Bj1lyvS+hVQAp/IBPVFDVZsmj3hzLk4hy6hUbyuJB5 +gtuejoXRsPRVI5rOZsl6w197XIySwc1ykXo5O3dy6m4OQPE8Qu+e1UaXDtkFakvAQR4 nVUwyxxS6tsa5zMv932f+NZDC0FKLCiDMLG0kRMH35Uy2H/A3Rlkud81F7BBEqJ19Ws9 iCvA== 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:content-transfer-encoding; bh=JNrbJ6uTS5dcaUEagdgV87VPF6KOZJCZNzugA913jsM=; b=NF9GKYXiWZRH3fa8teC6dgEa6PDuGAQg6Yupyh2FwiEiElpdOsRIqbwxutPB1TiqMc SLu8NeF4gNDZnlVuQQjSoKHvH7pVfhj3S8i1IOG+wb2hXYdRS9oy7Tt2Rz0WKryN9wTz /24aU0mw20zdf4ssctPez7kPxZIs4jEMWT84VlKR0VWbMemxB/rBNIE9lR8MY/DF3q+B uLnzrTyW64DhlAzjaD8kRUKzdAjMH8tCCTjLj23gBVJPAIdJWv353KhkeIaAVErml4MM chzQ2hmV4C1Z+bESZNaOhMuTGz+fsaGSF4d2OhkLsq4ixXGdL0AinLGg5wIljkoJqTeN W+9A== X-Gm-Message-State: AOAM531AsZ7PevG1J+ic41C8xDnJK2KufXL9gHRMGZ3rO5fPEWoKzumJ cq1aKhqQq9YEMxbkYvbijVNZYQLsqS2BwDObWE+JMVdnz+JcXg== X-Google-Smtp-Source: ABdhPJxsqXjVdjn5w1Uf/qWmi5cKblPj9dJjoZ9AH/erkSs2mJ4UQuMXlCig1IZXzV3TrYuu1ZTyXWmCavRFdOtmkPc= X-Received: by 2002:a05:6512:24b:: with SMTP id b11mr19180327lfo.486.1620195086170; Tue, 04 May 2021 23:11:26 -0700 (PDT) MIME-Version: 1.0 References: <7E71FA83-356E-448B-9726-02DF3FF5BD14@gmail.com> <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> <20210414120551.GA3882@tarpaulin.shahaf.local2> <20210415213456.GE6669@tarpaulin.shahaf.local2> In-Reply-To: From: Marlon Richert Date: Wed, 5 May 2021 09:10:49 +0300 Message-ID: Subject: Re: [RFC][PATCH] Reset ZLE hooks when changing prompt themes (was Re: [RFC][PATCH] `newuser` prompt theme) To: Bart Schaefer Cc: Daniel Shahaf , Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 48784 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 Sun, May 2, 2021 at 8:59 PM Bart Schaefer wr= ote: > > On Fri, Apr 16, 2021 at 3:38 PM Marlon Richert = wrote: > > > > Attached is a new version of the patch that handles _all the things._ \= o/ > > This looks OK, with two questions: > 1. Subshells have been introduced. Those won't be treated as > interactive shells. Are you sure about that? When I do `foo() { ( setopt ) }; foo`, it still lists 'interactive' (though not 'monitor' or 'zle'). > Does that matter? It doesn't appear to matter. The prompt previews look the same as before. Try `prompt -p` (without further args). Doesn > 2. This bit in the restore style: > + $( add-zsh-hook -L ) > + $( add-zle-hook-widget -L ) > There may not be anything to be done about this, but unless I'm > mistaken that just re-adds all the previous hooks, it doesn't remove > any? The code it is replacing clobbered the entire list of precmd and > preexec hooks, which I suppose also might also be wrong if anything > other than the prompt theme was manipulating them. `add-zsh-hook -L` outputs statements in the form of `typeset -g -a _functions=3D( ... )`, while `add-zle-hook-widget -L` outputs statements in the form of `zstyle zle- widgets : ...` (which is where add-zle-hook-widget stores the hook widgets to call internally). eval'ing either of these results in the same good, old-fashioned clobbering as in the old code. So, no functional change there. :) I just realized, though, that these lines (new and old) don't actually do anything useful: * When you call `prompt`, it will not unhook anything not called `prompt_*_`. So, whatever hooks you've set up that don't follow the naming scheme will still be there when you call `prompt restore`. No need to restore them. * When you call `prompt`, it will unhook everything called `prompt_*_`. So, if a prompt theme correctly implements the prompt system contract, its hook functions will already get unhooked when switching themes. Again, no need to do anything special when calling `prompt restore`. The only case I can think of that would need special handling is if you already had hooks installed that follow the `prompt_*_` naming convention before calling `prompt` for the first time. Should we just get rid of this part of the "restore" logic? And instead just document clearly that `prompt` will auto-remove all hooks that follow its naming scheme? And speaking of prompt hooks and naming schemes: On Fri, Apr 16, 2021 at 12:34 AM Daniel Shahaf wro= te: > Marlon wrote on Thu, Apr 15, 2021 at 21:54:48 +0300: > > On 14 Apr 2021, at 15:05, Daniel Shahaf wrote: > > >> +++ b/Functions/Prompts/promptinit > > >> @@ -178,8 +177,13 @@ Use prompt -h for help on specific them= es.' > > >> > > >> # Reset some commonly altered bits to the default > > >> local hook > > >> - for hook in chpwd precmd preexec periodic zshaddhistory zshe= xit; do > > >> - add-zsh-hook -D "${hook}" "prompt_*_${hook}" > > >> + for hook in chpwd precmd preexec periodic zshaddhistory zshe= xit \ > > >> + zsh_directory_name; do > > >> + add-zsh-hook -D "$hook" "prompt_*_$hook" > > >> + done > > >> + for hook in isearch-exit isearch-update line-pre-redraw line= -init \ > > >> + line-finish history-line-set keymap-select; do > > >> + add-zle-hook-widget -D "$hook" "prompt_*_$hook" > > > > > > Recommend to name these prompt_${foo}_bar-{isearch-exit,isearch-updat= e,=E2=80=A6,keymap-select} > > > for some fixed value of =C2=ABbar=C2=BB to avoid namespace issues (i.= e., name > > > collisions between existing prompts and future hooks). > > > > Wouldn=E2=80=99t that be a breaking change in the API, though? > > No, it wouldn't, because those are add-zle-hook-widget hooks and the > current API only deals with add-zsh-hook hooks. > > We could even recommend that add-zsh-hook hooks be named > prompt_${foo}_baz_{chpwd,=E2=80=A6} for some fixed value of baz. We don'= t even > have to change the code to support this (because the asterisk will match > =C2=AB${foo}_baz=C2=BB just fine); we just need to document the recommend= ation and > deprecate the previous recommended naming pattern. > > > Also, isn=E2=80=99t the prefix prompt_${foo}_ already a namespace of so= rts? Why change this? > > What if the foo theme declares a function called prompt_foo_lorem (or > even prompt_foo_ipsum_lorem) that _isn't_ an =C2=ABadd-*-hook lorem=C2=BB= hook > function, and later we start to to auto-register functions matching the > name pattern? > > Or if we were to make =C2=ABadd-zsh-hook bar lorem=C2=BB and =C2=ABadd-zl= e-hook-widget > bar ipsum=C2=BB both valid, for a single value of bar, and a prompt theme > wanted to install both hooks _and_ name the functions =C2=ABlorem=C2=BB a= nd =C2=ABipsum=C2=BB > conventionally? > > Or if someone wanted to quickly grep for add-zle-hook-widget callbacks? If we're going to change the prompt function naming scheme anyway, can we change it to something that starts with . or _? Because then `zstyle ':completion:*' prefix-needed yes` will conveniently hide these. How about .prompt..? And then auto-register these functions as hooks? And should all of this go into the same patch? If `prompt` automatically unregisters all hooks that follow a naming pattern (regardless of how they've been registered), then I think it would make sense for it to automatically register them, too.