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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4
Received: (qmail 11159 invoked from network); 13 Jun 2023 13:53:24 -0000
Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368)
by inbox.vuxu.org with ESMTPUTF8; 13 Jun 2023 13:53:24 -0000
ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1686664404;
b=GbqMXOb9RzazPsYdaY1AiXSSlfnMm8YoLt2z0hhkHlNmb9UaFAbQ6FRKPF7WqxIjI/ZCOFITtF
6diAn7hhT+M52GS1JNdgdOpGr0/ViuY52btvi8UrynSxEJSg3th+qibuUFRy6kB440NrX2mCv2
cmEFQinvMv8QElM99oK5/9R+3oWzDatoQrPgpbCukqE2939RGhUNQmxDt5WRCe4uIGXPfoKMM3
d4MT608j5BqCUO9PjFv6202wfUu0bKWuxQm9zjRqv2Sb3kOGwY5q6aGrvpu95vICuEbSOf5kFT
9eA70tVkKLiQbBiBw4V+/56NvgqCUvbXfusht6KlbGhJSA==;
ARC-Authentication-Results: i=1; zsh.org;
iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1686664404;
bh=z2ZSNKNq8xL4MUlfhmS2H8Gk/c5QXR/eRU8xp/iHIH0=;
h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help:
List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:
References:In-Reply-To:Message-ID:To:From:Date:DKIM-Signature:
DKIM-Signature;
b=qvdz9pr1wVzcySaf8oU1rw9FUpBVCj8lPmVs601e/+7poX/xeG1HPYbDcvJ9qzgjBkBOfUvUIQ
pEJRrgO9tu52caVV0Samsz/Jo0YQV1MpfEexnmLifUJkDId8JxlTPzQEhyZApaySEu2yipSVB2
b/Trp/EYB3p6MmmcSnH5AcadGM/dHMiS+n0cVJsrHGTQl14pAaNyTkE/0kHRlodR86MAH+Q8Nv
upecFd9WMbu1KIJKdB+wXMOYAriVX8MujIy4dawWjF37zotI1MPf9rXpJVAlI9Vrvfl1Vdnslv
3Hz5XhFYL7aIIxwp9jE9F4yhCKAZZhws5VxU2w8tYXujEA==;
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-Transfer-Encoding:
Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From:
Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:
Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=oTYiusP8nMnx5uxXAXvlZzFdphZMBKM6jtt2yWpeFg0=; b=DfxF0t8DDMQ1+n91OA61XppEcT
9jeb1zEEhWTIocyrBQy1c3c59R5/7BkaQl6xouBTitQaCkwlVP+dzFzPG/JYYid6DrPtfB8cAZZye
/vpQ3DccSWZig1xQMp43zSoVu1LtU60GgaRseMcz28JfGPT2HXPShKZpPED2puTdXD63pSRA/1sju
WoCgI7RgbgBac4iapUo2TyGYvmxs3Di/GBsAg4qGNM6sXbxZuQzkDAgDf+yA6O/41QWv7yp4n6QJ3
po7vqB8L8qgANzEH7bLMv/RrSPW2FN3QpQa0DT/EAo4DpDYSOC4Edd0Fyyw/NV8CDTBMihxdhNjwP
psWadWjQ==;
Received: by zero.zsh.org with local
id 1q94Sa-000Ni1-0A;
Tue, 13 Jun 2023 13:53:24 +0000
Authentication-Results: zsh.org;
iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
Received: from smtpq2.tb.ukmail.iss.as9143.net ([212.54.57.97]:44954)
by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256)
id 1q94S0-000N0E-KM;
Tue, 13 Jun 2023 13:52:51 +0000
Received: from [212.54.57.82] (helo=smtp3.tb.ukmail.iss.as9143.net)
by smtpq2.tb.ukmail.iss.as9143.net with esmtp (Exim 4.90_1)
(envelope-from
)
id 1q94S0-0000MI-8q
for zsh-users@zsh.org; Tue, 13 Jun 2023 15:52:48 +0200
Received: from oxbe10.tb.ukmail.iss.as9143.net ([172.25.160.141])
by smtp3.tb.ukmail.iss.as9143.net with ESMTP
id 94S0qSBoD9tPm94S0q2Dx9; Tue, 13 Jun 2023 15:52:48 +0200
X-Env-Mailfrom: p.w.stephenson@ntlworld.com
X-Env-Rcptto: zsh-users@zsh.org
X-SourceIP: 172.25.160.141
X-CNFS-Analysis: v=2.4 cv=IPTESCjG c=1 sm=1 tr=0 ts=648874b0 cx=a_exe
a=f70ZRucvQZHi2l2hbwz5vQ==:117 a=1DWFKdCB1IcA:10 a=IkcTkHD0fZMA:10
a=pGLkceISAAAA:8 a=alAROCJv_NrXtyn_XX8A:9 a=QEXdDO2ut3YA:10
a=75Kt_H3ikK-EkTT1woid:22
X-Authenticated-Sender: p.w.stephenson@ntlworld.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com;
s=meg.feb2017; t=1686664368;
bh=z2ZSNKNq8xL4MUlfhmS2H8Gk/c5QXR/eRU8xp/iHIH0=;
h=Date:From:To:In-Reply-To:References:Subject;
b=MVNFhj3i3j1rfSq5hMArUGr+n31lJfHQoRHWD1xRX7RjUO9CP3tOaeC3j44azCzji
jRUFTzMtrpZ1WEe+CqiK6lMwd+Q2HkRLbJcVIG6h+0E/wZxFMnI+UatVF+Ccu1aACG
rJIEOhWsfgx9pbVXd1L8m/YKZ+a1MNfOpKA82dYGLZ33jHt0RU9bm/CvRFj1iWG+VZ
01aHZq4Ghx4pWYuN4Rr7QasnsqjQLI4o4oQqXZ2ApIisc0XTzRzcPeYxi0o/2s4zfe
Fjyox6bJQkUU2WrmBqMqoi87cXSUpLsgoHlm3Ecm4/YYlRHvZcCiU62gLQJrbJuEHF
kGfISBDImup+w==
Date: Tue, 13 Jun 2023 14:52:48 +0100 (BST)
From: Peter Stephenson
To: Zsh Users
Message-ID: <141543605.1836026.1686664368186@mail.virginmedia.com>
In-Reply-To:
References:
Subject: Re: Perform history expansion on the current word only
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Priority: 3
Importance: Normal
X-Mailer: Open-Xchange Mailer
X-Originating-IP: 147.161.224.167
X-Originating-Client: open-xchange-appsuite
X-CMAE-Envelope: MS4xfOBB6fL251SP5sjP2ZOAqzYSaSqFHuGGgo8Fbgvn0Du+Zl47szUWbyILmDiMcwUacgdPlzBOJL9iv3bUIPiJlg+x9qJaXWNF+7mAbGLcLhlpTCwusXuy
4xPy8iftj0GOqXEu5OaNGmZdEnde676qlY1c1zRtCT8738SATF2jsapkd71GqSrIjVgtnwlG0/PvMQ0lB/NzsIF76k19PIQTLrDUqOl2ko7AwUd+fpr+V5e/
X-Seq: 29089
Archived-At:
X-Loop: zsh-users@zsh.org
Errors-To: zsh-users-owner@zsh.org
Precedence: list
Precedence: bulk
Sender: zsh-users-request@zsh.org
X-no-archive: yes
List-Id:
List-Help: ,
List-Subscribe: ,
List-Unsubscribe: ,
List-Post:
List-Owner:
List-Archive:
> On 13/06/2023 14:14 Marlon Richert wrote:
> All built-in widgets that perform history expansion seem to perform it
> on the entire line. However, I would like to have keybinding that
> performs history expansion on the current word only. How do I make
> this happen?
This is !-history, right? Someone may have sneakier ideas than I do, but
I don't think this can be done simply because the history mechanism itself
just reads through a line from left to right.
It's possible to write a widget that divides a line into shell
words and only applies history to that word, however. It would get
a bit confused if you were trying to extract words from the current line,
but I suspect that isn't the point here. match-words-by-style can
help with this --- it's documented in zshcontrib.
The second problem is that the only existing !-history expansion
functions, as you noted, expand the whole line, so we need to shrink
the line temporarily.
Somewhat to my surprise, the following initial go does in fact seem to
be in roughly the right area. This is expanding strictly the word
*before* the cursor --- match-words-by-style is written to allow
the caller to be clever about context, hence the long array of
returned line portions, but I've skipped that here.
Save as a function, autoload, and "zle -N" as usual.
pws
emulate -L zsh
setopt extendedglob
autoload -Uz match-words-by-style
local curcontext=":zle:$WIDGET"
local -a matched_words
match-words-by-style
BUFFER="${matched_words[2]}"
zle expand-history
LBUFFER="${matched_words[1]}$BUFFER" RBUFFER="${matched_words[3,7]}"