From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28659 invoked from network); 1 Dec 2004 02:39:24 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 1 Dec 2004 02:39:24 -0000 Received: (qmail 41425 invoked from network); 1 Dec 2004 02:39:18 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Dec 2004 02:39:18 -0000 Received: (qmail 10338 invoked by alias); 1 Dec 2004 02:38:27 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8255 Received: (qmail 10324 invoked from network); 1 Dec 2004 02:38:26 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Dec 2004 02:38:26 -0000 Received: (qmail 40165 invoked from network); 1 Dec 2004 02:38:26 -0000 Received: from moonbase.zanshin.com (64.84.47.139) by a.mx.sunsite.dk with SMTP; 1 Dec 2004 02:38:24 -0000 Received: from toltec.zanshin.com (toltec.zanshin.com [64.84.47.166]) by moonbase.zanshin.com (8.13.1/8.13.1) with ESMTP id iB12cJM1032576; Tue, 30 Nov 2004 18:38:22 -0800 Date: Tue, 30 Nov 2004 18:38:19 -0800 (PST) From: Bart Schaefer Reply-To: Bart Schaefer To: zzapper cc: zsh-users@sunsite.dk Subject: Re: Edit result of last command In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 On Tue, 30 Nov 2004, zzapper wrote: > Any chance you could repost your version of keep ? I see you found something, but you also asked back then if I could summarize the thread, and I found a message sitting in my drafts folder where clearly I intended to do that. So, here in one place, is the end result of the thread, with a couple of corrections thrown in. The "keep" function and alias: function keep { setopt localoptions nomarkdirs nonomatch nocshnullglob nullglob kept=() # Erase old value in case of error on next line kept=($~*) if [[ ! -t 0 ]]; then local line while read line; do kept+=( $line ) # += is a zsh 4.2+ feature done fi print -Rc - ${^kept%/}(T) } alias keep='noglob keep' The "_insert_kept" widget: _insert_kept() { (( $#kept )) || return 1 local action zstyle -s :completion:$curcontext insert-kept action if [[ -n $action ]] then compstate[insert]=$action elif [[ $WIDGET = *expand* ]] then compstate[insert]=all fi if [[ $WIDGET = *expand* ]] then compadd -U ${(M)kept:#${~words[CURRENT]}} else compadd -a kept fi } zle -C insert-kept-result complete-word _generic zle -C expand-kept-result complete-word _generic zstyle ':completion:*-kept-result:*' completer _insert_kept bindkey '^Xk' insert-kept-result bindkey '^XK' expand-kept-result # shift-K to get expansion And the "_expand_word_and_keep" replacement for _expand_word: _expand_word_and_keep() { function compadd() { local -A args zparseopts -E -A args J: if [[ $args[-J] == all-expansions ]] then builtin compadd -A kept "$@" kept=( ${(Q)${(z)kept}} ) fi builtin compadd "$@" } local result _main_complete _expand result=$? unfunction compadd return result } # This line must come after "compinit" in startup: zle -C _expand_word complete-word _expand_word_and_keep # No bindkey needed, it's already ^Xe from _expand_word