zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zzapper <david@tvis.co.uk>
Cc: zsh-users@sunsite.dk
Subject: Re: Edit result of last command
Date: Tue, 30 Nov 2004 18:38:19 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0411301816160.26889@toltec.zanshin.com> (raw)
In-Reply-To: <j7toq0hhu6ldk794e0784rqo1h3oipmcud@4ax.com>

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


      parent reply	other threads:[~2004-12-01  2:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-29 19:35 zzapper
2004-11-29 19:58 ` Thomas Köhler
2004-11-29 20:02 ` Bart Schaefer
2004-11-29 21:34   ` Juhapekka Tolvanen
2004-11-30  2:06     ` Bart Schaefer
2004-11-29 21:53   ` zzapper
2004-11-30 13:29   ` zzapper
2004-11-30 17:33     ` zzapper
2004-12-01  2:38     ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.61.0411301816160.26889@toltec.zanshin.com \
    --to=schaefer@brasslantern.com \
    --cc=david@tvis.co.uk \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).