zsh-workers
 help / color / mirror / code / Atom feed
* starting completions with =,<,>
@ 2004-07-25 11:42 chris s
  2004-07-25 17:42 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: chris s @ 2004-07-25 11:42 UTC (permalink / raw)
  To: zsh-workers

Hi, I'm trying to add to the functionality of the emerge completion for
gentoo linux. For example,

emerge -p =zsh-4.2.0-r1
emerge -p '>zsh-4.2.0'
emerge -p '<zsh-4.2.0'
emerge -p '>=zsh-4.2.0'
emerge -p zsh

are all valid commands. I saw in the manpage that _values does not
support the equal sign. Unfortunately, that's exactly what I need.

Here's a small working example of what I'm trying to do.
http://home.earthlink.net/~oberyno/data/_emerge
The relevant part being 

'--exact[specify exact version]:*::alt:->exact_ver' 

This is what I'd rather have look like this:

'=[specify exact version]:*::alt:->exact_ver' 

Is there any way to fake this? Thanks for any advice.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: starting completions with =,<,>
  2004-07-25 11:42 starting completions with =,<,> chris s
@ 2004-07-25 17:42 ` Bart Schaefer
  2004-07-25 21:39   ` chris s
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-07-25 17:42 UTC (permalink / raw)
  To: zsh-workers

On Sun, 25 Jul 2004, chris s wrote:

> Hi, I'm trying to add to the functionality of the emerge completion for
> gentoo linux. For example,
> 
> emerge -p =zsh-4.2.0-r1

Unless you "unsetopt equals" this could potentially be expanded into

emerge -p /usr/local/bin/zsh-4.2.0-r1

(or the like).  That's why there's the "-equals-" completion context.

> I saw in the manpage that _values does not support the equal sign.

Can you quote the bits of the manual that made you think this?

In any event I don't think you want _values.  The _values function is for
words of the form <name><sep><value> where <sep> defaults to "=", e.g.
"foo=bar" (like an assignment).  You can tell it to use a different <sep>,
but in the case of emerge there doesn't appear to be a <name> part.

> '--exact[specify exact version]:*::alt:->exact_ver' 
> 
> This is what I'd rather have look like this:
> 
> '=[specify exact version]:*::alt:->exact_ver' 

The problem here is that you're trying to treat this as an option, when 
what you need to do is treat it as an argument.  The question is whether 
it is a stand-alone argument, or whether it's an argument that must follow 
the -p option?  I haven't been able to dig up any documentation on emerge 
(the only software I can find are a mass-mailing program and the emacs CVS 
interface -- everything else is lost in the Google noise because "emerge" 
is a real word).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: starting completions with =,<,>
  2004-07-25 17:42 ` Bart Schaefer
@ 2004-07-25 21:39   ` chris s
  2004-07-26 13:06     ` chris s
  0 siblings, 1 reply; 5+ messages in thread
From: chris s @ 2004-07-25 21:39 UTC (permalink / raw)
  To: zsh-workers

On Sun, 25 Jul 2004 10:42:38 -0700, Bart Schaefer wrote:


> Unless you "unsetopt equals" this could potentially be expanded into
>
> emerge -p /usr/local/bin/zsh-4.2.0-r1
>
> (or the like).  That's why there's the "-equals-" completion context.

Yes, I saw that, it's in my example under the compdef header. Is it
-equal- or -equals- though? And are there any examples of this anywhere? I
saw that _bzip2 uses -redirect-, but it wasn't obvious how to apply that
to my situation with -equal-. There doesn't seem to be any command that
does use -equal-, that I've found.

>> I saw in the manpage that _values does not support the equal sign.
> 
> Can you quote the bits of the manual that made you think this?
>
>
Sure, the man page for zshcompsys says this under _values 6th paragraph

  All other arguments describe the possible values and their arguments 
  in the same format used for the description of options by the _arguments
  function (see above).  The only  differences  are that  no minus or plus
  sign is required at the beginning, values can have only one argument,
  and the forms  of  action  beginning with an equal sign are not
  supported.

I'm probably reading it wrong, though.

> In any event I don't think you want _values.  The _values function is
> for words of the form <name><sep><value> where <sep> defaults to "=",
> e.g. "foo=bar" (like an assignment).  You can tell it to use a different
> <sep>, but in the case of emerge there doesn't appear to be a <name>
> part.

Exactly, there is no <name>, just a <value>.
 
> The problem here is that you're trying to treat this as an option, when
> what you need to do is treat it as an argument.  The question is whether
> it is a stand-alone argument, or whether it's an argument that must
> follow the -p option?  I haven't been able to dig up any documentation
> on emerge (the only software I can find are a mass-mailing program and
> the emacs CVS interface -- everything else is lost in the Google noise
> because "emerge" is a real word).

Sorry for not being more clear. Emerge is the gentoo linux install
command. You can find out more about gentoo at www.gentoo.org.  There is a
manpage here: http://re.a.la/man/emerge/ What I am trying to add is listed
under the ebuild and dependency headers.

This could be a standalone argument, or it could follow one or more other
arguments (-p, --pretend, --update, etc...). 
emerge -p =gvim-6.3
emerge  =gvim-6.3
emerge --pretend --deep --buildpkg =gvim-6.3 
All valid commands as far as emerge is concerned.

The existing emerge completion is here: 
http://cpan.cybercomm.nl/pub/gentoo-portage/app-shells/zsh/files/_portage

If I insert this snippet (along with the _portage_ebuilds from my previous
example) into the above completion, --pretend works and lists all the
appropriate files, while = lists the normal ones.
 
 =|--pretend)
  _arguments -s \
     '*:install version:_portage_ebuilds' "$common_args[@]" && return 0
		;;

And just to clarify, I want regular emerge without an equal sign to
complete one list (fvwm, zsh, abiword...) and the emerge = to complete
exact versions (fvwm-2.5.10-r6, fvwm-2.4.18, zsh-4.2.0-r1, ...). So I
can't just replace the default behavior with the versioned packages.

Hope that clears things up. Thanks for looking at this.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: starting completions with =,<,>
  2004-07-25 21:39   ` chris s
@ 2004-07-26 13:06     ` chris s
  2004-07-26 13:59       ` Oliver Kiddle
  0 siblings, 1 reply; 5+ messages in thread
From: chris s @ 2004-07-26 13:06 UTC (permalink / raw)
  To: zsh-workers

Ok, I was looking more into this, and it turns out the bash completion is
able to handle =, >=,<=. The bash person did this:

	local cur curword numwords compwords opts cond prepend 
	....
	cur="${COMP_WORDS[COMP_CWORD]}"
	....
	# Check for conditional.
	cond="${cur%%[A-Za-z0-9]*}"
	cur="${cur:${#cond}}"
	[[ "${cond:0:1}" == "'" ]] && prepend="-P ${cond:1}" 
	# Handle cases where a conditional is specified.
	 if [[ "${cond}" ]]; then
		if [[ "${cur}" ]]; then
			if [[ "${cur}" == */* ]]; then
...
and it seems to work. FYI, the bash completion for emerge is at
http://sourceforge.net/projects/gentoo-bashcomp/

Anyway, I think I'm going to completely rewrite the zsh emerge completion
to handle this sort of thing. In the above code, all I would have to do to
make it zsh compatible would be change $COMP_WORDS variable to $words and
$COMP_CWORD to $CURRENT , right? And prepend would be compadd -P?

Thanks for your help.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: starting completions with =,<,>
  2004-07-26 13:06     ` chris s
@ 2004-07-26 13:59       ` Oliver Kiddle
  0 siblings, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2004-07-26 13:59 UTC (permalink / raw)
  To: chris s; +Cc: zsh-workers

chris s wrote:
> Ok, I was looking more into this, and it turns out the bash completion is
> able to handle =, >=,<=. The bash person did this:

That sort of approach wouldn't work in zsh. It does a lot of the work
for you when it comes to quoting.

In the previous e-mail:
> emerge -p =zsh-4.2.0-r1
> emerge -p '>zsh-4.2.0'
> emerge -p '<zsh-4.2.0'
> emerge -p '>=zsh-4.2.0'
> emerge -p zsh
> 
> are all valid commands. I saw in the manpage that _values does not
> support the equal sign. Unfortunately, that's exactly what I need.

I looked at your script and it is using _arguments. It's a bit messy to
handle the quoting. Try the following as a starting point:

  _arguments -C \
    '--pretend[pretend an emerge]' \
    '--exact[specify exact version]' \
    '*: :->args'

  case $state in
    args)
      if compset -P '(\\|)[<=>]*'; then
	compadd zsh-4.2.0-r1 etc etc
      else
	_values -S '' 'version prefix' \
	  '=[specify exact version]:' \
	  '<[specify maximum version]:' \
	  '>[specify too old version]:' \
	  '>=[specify minimum version]:'
	compadd zsh etc etc
      fi
    ;;
  esac

You'll need to put a proper tags loop around the bit with _values and
the other compadd. I'm not really using _values in the way it was
intended but this does work.

Note that you probably shouldn't be using the :*: stuff in _arguments.
Look inside the opt_args associative array from inside the args state
instead.

You don't need to do anything with the -equals- context. You just need
to either write:
  emerge -p \=zsh-4.2.0-r1   (or emerge -p '=zsh-4.2.0-r1')
or use unsetopt equals in your setup. This applies regardless of any
completion function setup. This is what the emerge man page means when
it says "in many shells you will need to escape characters such as '<'
and '='"

Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-07-28  3:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-25 11:42 starting completions with =,<,> chris s
2004-07-25 17:42 ` Bart Schaefer
2004-07-25 21:39   ` chris s
2004-07-26 13:06     ` chris s
2004-07-26 13:59       ` Oliver Kiddle

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).