From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17857 invoked by alias); 15 Jul 2014 17:08:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32866 Received: (qmail 17298 invoked from network); 15 Jul 2014 17:08:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f626d000004b39-7e-53c55da165ad Date: Tue, 15 Jul 2014 17:58:08 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: implicit previous command, only state what should change Message-id: <20140715175808.660f4832@pwslap01u.europe.root.pri> In-reply-to: <874myk3ocp.fsf@debian.uxu> References: <874myk3ocp.fsf@debian.uxu> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4Fd2FsUeDDZpXKlocbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujOfvD7MWXJetmPj7BGsD4zyJLkZODgkBE4k9c+YyQdhiEhfu rWfrYuTiEBJYyihxqGMVE4SznEmi4e8VRpAqFgFViQNvtzKD2GwChhJTN80Gi4sIiEucXXue BcQWFnCVmH75AzuIzStgL9GyayoriM0poCHxc3MPWI2QgLrE9P3dbCA2v4C+xNW/n6CusJeY eeUMI0SvoMSPyffA6pkFtCQ2b2tihbDlJTavecs8gVFgFpKyWUjKZiEpW8DIvIpRNLU0uaA4 KT3XSK84Mbe4NC9dLzk/dxMjJAi/7mBceszqEKMAB6MSD++NaUeChVgTy4orcw8xSnAwK4nw SpocDRbiTUmsrEotyo8vKs1JLT7EyMTBKdXA2P1TPU++uXmGLcNPrkLjOCkmlv2RQa9XFM/u uS9qumhd+Utt6VwdvvZXFYy7RTwDDmx9b/7qSmPyfcalnCV23PovV0qUME5d9mDPxysXqk99 vRtuqWg4Y9+chsbojpOrDvJy/L7A9/Ak14xVx7Z1rpvw2DLj2cOS6Rnr//il7H2460iq5fm4 Y0osxRmJhlrMRcWJAE4WAVcgAgAA On Mon, 14 Jul 2014 00:06:46 +0200 Emanuel Berg wrote: > Let's say I write: > > $ grep user-home-directory *.el > > After that, I realize that it should have been > `user-emacs-directory'. > > Is there a way to tell zsh to "execute the previous > command again, only substitute the first argument for > user-emacs-directory"? The read-from-minibufer change is a bug fix: NUMERIC was being propagated down to the first command read within the recursive edit. I suspect that might be regarded as a bug in recursive-edit. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 2fcfbbd..4ee404c 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2328,6 +2328,31 @@ The name is a slight misnomer, as in fact the shell's own minibuffer is not used. Hence it is still possible to call tt(executed-named-cmd) and similar functions while reading a value. ) +tindex(replace-argument) +tindex(replace-argument-edit) +item(tt(replace-argument), tt(replace-argument-edit)) +( +The function tt(replace-argument) can be used to replace a command +line argument in the current command line or, if the current command +line is empty, in the last command line executed (the new command line +is not executed). Arguments are as delimited by standard shell syntax, + +If a numeric argument is given, that specifies the argument to be +replaced. 0 means the command name, as in history expansion. + +If no numeric argument is given, the current argument is replaced; +this is the last argument if the previous history line is being used. + +The function prompts for a replacement argument. + +If the widget contains the string tt(edit), for example is defined as + +example(zle -N replace-argument-edit replace-argument) + +then the function presents the current value of the argument for +editing, otherwise the editing buffer for the replacement is +initially empty. +) tindex(replace-string) tindex(replace-string-again) tindex(replace-pattern) diff --git a/Functions/Zle/read-from-minibuffer b/Functions/Zle/read-from-minibuffer index 57e9268..19d1bd5 100644 --- a/Functions/Zle/read-from-minibuffer +++ b/Functions/Zle/read-from-minibuffer @@ -39,6 +39,8 @@ local readprompt="$1" lbuf_init="$2" rbuf_init="$3" read -k $keys stat=$? else + local NUMERIC + unset NUMERIC zle recursive-edit -K main stat=$? (( stat )) || REPLY=$BUFFER diff --git a/Functions/Zle/replace-argument b/Functions/Zle/replace-argument new file mode 100644 index 0000000..b43fc39 --- /dev/null +++ b/Functions/Zle/replace-argument @@ -0,0 +1,46 @@ +# Replace an argument to a command, delimited by normal shell syntax. +# Prompts for the replacement. +# With no numeric argument, replace the current argument. +# With a numeric argument, replace that argument: 0 = command word, +# as in history expansion. +# If editing buffer is empty, use previous history line. + +autoload -Uz split-shell-arguments read-from-minibuffer + +if (( ${#BUFFER} == 0 )); then + (( HISTNO-- )) + CURSOR=${#BUFFER} +fi + +local widget=$WIDGET +integer numeric cursor=CURSOR +if (( ${+NUMERIC} )); then + numeric=$NUMERIC +else + numeric=-1 +fi +local reply REPLY REPLY2 +integer index +split-shell-arguments + +if (( numeric >= 0 )); then + index=$(( 2 + 2*numeric )) +else + index=$((REPLY & ~1 )) +fi + +local edit +if [[ $widget = *edit* ]]; then + edit=$reply[$index] +fi +read-from-minibuffer "Replace $reply[$index] with: " $edit || return 1 + +integer diff=$(( ${#REPLY} - ${#reply[$index]} )) +reply[$index]=$REPLY + +BUFFER=${(j..)reply} +if (( cursor > REPLY2 )); then + (( CURSOR = cursor + diff )) +else + (( CURSOR = REPLY2 )) +fi pws