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 23881 invoked from network); 15 Apr 2021 18:55:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Apr 2021 18:55:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618512907; b=Z24W+pidX8liozAUTbCPR1fcW6feM873LDTq+AY9oegc5jbfxs5emxdeIzYdYMnAvz+OvjmPFK MhPMSe6hMrYFX0CXeF90IaAcWBEMfkvsgj5dmSMgxo5soWhxQn1wDJT2ewe5wp/AuOQ5YFTous HfVPFBe5SVtWFc3Bkp7KJxJj23cXhVLNhcOGct3zTvjPF35qByqyPcf4uyj0k/8pvIbLmoF3OG 1avOUNDWzDy0HoyCi8wXnq/v+3WNY6UAfUQRu8AzjxjL1gZ0riakli2x0OhcrwE+pKQc+DdiLX G6eRJe0vYOmM8kSiwrCTjWbMEf/fpS8/ZKuEpxVNYz0sCA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; 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=1618512907; bh=cRQLIlARqLpgo2T7OaYkSmDbknuxNzIasDMk/70sd7A=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:References:To:Cc:In-Reply-To:Date:Subject:MIME-Version: Content-Type:Message-ID:From:DKIM-Signature:DKIM-Signature; b=PxaSSJtzkAdF36i4eQyy85fdFVmY/8zjB7OZfp+MUQCT/dsIAyKOwtCLaQHHkUqF6/b1YAGw+D VqvKFaLWFWOs+eCZrmr1YrXjnkZ46mSMkvrlw6T22WYATmR0KqIhsEiZEl086oc4Rcg6cwR5G9 c2m+YW3ejlnNubvkDU4WrBcWGIljqgYnD8RcUKzFZKBJMkS/nKHwHxYHguVbAMFAvZH4Bf180O dpAUIHrJBcl3SxuLX1hFKCuTOE05lMq9hKCYSrTdm52TxocdOZs1x/Ykyvdk6D4UIBWUkIneCT DF/ElnasG6CIIW2ogYFPOO/5LWR5t2JG0QmCy2QE08z/HQ==; 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:References:To:Cc:In-Reply-To:Date: Subject:Mime-Version:Content-Type:Message-Id:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=6e/gZI5AX8i8nEa+/x/gn94fcML2AbmYxu1WxDItFlc=; b=zEs20pPVWqKo/1/QzaGOSG0apO l7yFa2MTG86KoWBzERTK+hgEPLZJf2AYL4M49oE+cy9JHeR2tMQq0MyPQnXGJBww7ORFgcd/Giegb oqtQaWVEa2VSXrUnVWjfhLvJPFwHrX/nhD0W5V5fNu/RVzqQzMBalmy1bddIaE2rcaullnkRIAsA8 +SDJP7RMLrc1o3inZXVor9sgc8oE/zMe5w8wWlLwg7ZnMc0HtnRc8Svzl5kZdbV6xN3+0B0QABmsa Etss97vihtcDmonnIdbw4gWu9vmkd3ue/53zVSsFRg0VdEc+xSoTc2hIorjrtdEBqbHBdtW3MaP4N YxlNyE3A==; Received: from authenticated user by zero.zsh.org with local id 1lX78o-000Igt-KE; Thu, 15 Apr 2021 18:55:02 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; 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-f52.google.com ([209.85.167.52]:42672) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lX78c-000IQg-Uw; Thu, 15 Apr 2021 18:54:51 +0000 Received: by mail-lf1-f52.google.com with SMTP id z13so23779926lfd.9 for ; Thu, 15 Apr 2021 11:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=6e/gZI5AX8i8nEa+/x/gn94fcML2AbmYxu1WxDItFlc=; b=oY5sCoHilHX5qq/m0ivbLXHyHxS+l2YTuutTDnCJDpovNQrOexFQWS65M/nxUE/6Pd jtae3xXrBODm32mXTQV17J49lfSXxOucRzEsyf+CAswfYyMZKXtD0ZQ4udRySLcyi322 A/1qNEjkTes+9ZttFFSX+uGu4YMZgfi7pn7c+GYUZbj95ONGopXc5B2LXvOmDLIkdMve m7n/iBly1QxP1RdHs82R6JlMJXd3Ggs4QcONCl9Ch1JP/R34sHhg/qWDi/CWlFPTOFvI A2Y35RUPf9l7LAU4Vk3+UdakglW1iLNUqI9MjgcNULIGhPJzCTn2GP4jgeVYiIXMl+LP NRvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=6e/gZI5AX8i8nEa+/x/gn94fcML2AbmYxu1WxDItFlc=; b=pkGWABbbjitOqSyq7GZ3HIBQXgUpD5vu8FjK1Ni6wfhNxGjArma8RNxIZx0Cr98moV b8bmAafHX1M0jm2Q5GIFh8D3T3Pcr021y+aIkB9aSdLP4arskxnV0mJ6gqj9sV+R6Smi yU/XBoRVlJzt8l0WXSccO3BdZ3p8V7EnC2f5OWPGwECGi4G+i02qdlmNa7xjXjNmbU6p nnkYQlXKj/pKReN7WZVLn+8y2cVjASGYkiRsEyvHIlj5Vqhjj6EWcqxKA/sp9Glz8PT6 U7rYPs2c1zgQERjl8YI1AgBo2hqiQcMM8yAMtQzhvlUZn+6zPeRxG10/uZ34HgvJfyx/ cjaA== X-Gm-Message-State: AOAM533gnd8U9kLiLM49t7MugyLyGFnuxve6xymAXlTnJ0lqA5+YU7b/ oEBu04IWUBOLMcF6AxEgXx9DWHzf/YAcIQ== X-Google-Smtp-Source: ABdhPJxSdi8Xr6YITC/NJWyosyVm84zK7b6N2Md5YYU28qiF6VjPfk3efgcDziRr530llPi/Dtr4WA== X-Received: by 2002:a05:6512:38c2:: with SMTP id p2mr360576lft.259.1618512890110; Thu, 15 Apr 2021 11:54:50 -0700 (PDT) Received: from [192.168.1.15] (hag-tkubng22-50df3e-132.dhcp.inet.fi. [80.223.62.132]) by smtp.gmail.com with ESMTPSA id q3sm685892ljp.67.2021.04.15.11.54.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Apr 2021 11:54:49 -0700 (PDT) From: Marlon Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_E781080F-4E23-4B1D-81F3-78BF8C57C4C1" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: [RFC][PATCH] Reset ZLE hooks when changing prompt themes (was Re: [RFC][PATCH] `newuser` prompt theme) Date: Thu, 15 Apr 2021 21:54:48 +0300 In-Reply-To: <20210414120551.GA3882@tarpaulin.shahaf.local2> Cc: Zsh hackers list To: Daniel Shahaf References: <7E71FA83-356E-448B-9726-02DF3FF5BD14@gmail.com> <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> <20210414120551.GA3882@tarpaulin.shahaf.local2> X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Seq: 48592 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: --Apple-Mail=_E781080F-4E23-4B1D-81F3-78BF8C57C4C1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Patch attached, but not yet including Daniel=E2=80=99s suggested change = below (since I still have questions about it). It includes an update to = the docs, but note that I am not able to build those myself. I would = much appreciate it f someone else could do that to test whether I did it = correctly. 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 = themes.' >>=20 >> # Reset some commonly altered bits to the default >> local hook >> - for hook in chpwd precmd preexec periodic zshaddhistory = zshexit; do >> - add-zsh-hook -D "${hook}" "prompt_*_${hook}" >> + for hook in chpwd precmd preexec periodic zshaddhistory = zshexit \ >> + 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" >=20 > All these should be documented, like prompt_${foo}_preview is. >=20 > Recommend to name these = prompt_${foo}_bar-{isearch-exit,isearch-update,=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? I mean, = there are already 3rd party prompt themes that use the current = prompt_${foo}_{isearch-exit,isearch-update,=E2=80=A6,keymap-select} = naming scheme. Also, isn=E2=80=99t the prefix prompt_${foo}_ already a = namespace of sorts? Why change this? --Apple-Mail=_E781080F-4E23-4B1D-81F3-78BF8C57C4C1 Content-Disposition: attachment; filename=0001-Reset-ZLE-hooks-when-changing-prompt-themes.txt Content-Type: text/plain; x-unix-mode=0644; name="0001-Reset-ZLE-hooks-when-changing-prompt-themes.txt" Content-Transfer-Encoding: quoted-printable =46rom b60bfd135ae2631a3b28aaf81074594d0ec1f967 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Thu, 15 Apr 2021 21:50:36 +0300 Subject: [PATCH] Reset ZLE hooks when changing prompt themes --- Doc/Zsh/contrib.yo | 8 ++++---- Functions/Prompts/promptinit | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 3c4fdded0..01809c0c4 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2032,10 +2032,10 @@ setopts (tt(promptbang), etc.) are turned on, = all other prompt-related options are turned off. The tt(prompt_opts) array preserves setopts = even beyond the scope of tt(localoptions), should your function need that. ) -item(Modify precmd and preexec)( -Use of tt(add-zsh-hook) is recommended. The tt(precmd) and tt(preexec) -hooks are automatically adjusted if the prompt theme changes or is -disabled. +item(Modify hooks)( +Use of tt(add-zsh-hook) and tt(add-zle-hook-widget) is recommended. = All hooks +that follow the naming pattern tt(prompt__) are = automatically +removed when the prompt theme changes or is disabled. ) item(Declare cleanup)( If your function makes any other changes that should be undone when the diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 37d69f100..b9d833c4b 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -14,6 +14,8 @@ prompt_themes=3D() promptinit () { emulate -L zsh setopt extendedglob + autoload -Uz add-zsh-hook add-zle-hook-widget + local ppath=3D'' name theme local -a match mbegin mend =20 @@ -32,9 +34,6 @@ promptinit () { fi done =20 - # To manipulate precmd and preexec hooks... - autoload -Uz add-zsh-hook - # Variables common to all prompt styles prompt_newline=3D$'\n%{\r%}' } @@ -178,8 +177,13 @@ Use prompt -h for help on specific themes.' =20 # Reset some commonly altered bits to the default local hook - for hook in chpwd precmd preexec periodic zshaddhistory zshexit; = do - add-zsh-hook -D "${hook}" "prompt_*_${hook}" + for hook in chpwd precmd preexec periodic zshaddhistory zshexit = \ + 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" done typeset -ga zle_highlight=3D( ${zle_highlight:#default:*} ) (( ${#zle_highlight} )) || unset zle_highlight --=20 2.31.1 --Apple-Mail=_E781080F-4E23-4B1D-81F3-78BF8C57C4C1--