Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Using buffer for history-incremental-search-backward



On Jul 5, 11:32pm, Felix Rosencrantz wrote:
} Subject: Re: Using buffer for history-incremental-search-backward
}
} I was sort of under the impression that the completion system could
} only complete a single word at time, and not sets of words, like a
} previous command line would be.

It is pretty much oriented around completing the current single word.
However, if that word happens to be the first one on the line (or the
first one in a "command position") then you can safely use that word
as a search key to complete entire commands.  You just need to use the
-U option of compadd to cause that word to be erased and replaced by
the command that was looked up.

For example, this may be enough for your w2k F7 key widget; I confess
not to know how anything on w2k really works:

    #compdef -k menu-select \e[18~
    (( CURRENT == 1 && $#words == 1 )) &&
    compadd -QU "${(@)history[(R)*$words[CURRENT]*]}"

You can try it without the `&& $#words == 1' part, too, but note that
it only completes when the cursor is in the first word.

One problem with the above is that it bypasses the completion function
system, so you don't get the benefit of all the context analysis that
goes on in _main_complete et al.  For that you need to tie in:

    #compdef -k menu-select \e[18~
    # The following depends on the FUNCTION_ARGZERO option.
    # Use the file base name instead of $0 if that's not set.
    if [[ $_comps[-command-] != $0 ]]; then
        # We've not been called before, so:
	#  set a trap to restore state safely ...
	trap "_comps[-command-]='$_comps[-command-]'" EXIT INT
	#  make ourself be called for command words ...
	_comps[-command-]=$0
	#  and then call the regular completion system.
	_main_complete
    else
	# The completion system has called us back; add matches.
	compadd -QU "${(@)history[(R)*$words[CURRENT]*]}"
    fi

} But what if I had a command that only has long options that I
} wanted to complete all at once as a group ( for example for GNU tar
} "--extract --gzip --file archive" , "--create --gzip --file archive",
} etc.) Can the completion system handle that?

As long as what you need to replace is only one word, the thing that
replaces it can have more than one word.

} Thanks very much, Bart, for your help with the h-i-s-b, it works just
} like I want.

You're welcome!

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author