zsh-workers
 help / color / mirror / code / Atom feed
* Re: completion but extra options allowed
       [not found]   ` <20000210195143.A26109@br-online.de>
@ 2000-02-11 18:45     ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-02-11 18:45 UTC (permalink / raw)
  To: zsh-workers

On Feb 10,  7:51pm, Andy Spiegl wrote:
} Subject: Re: completion but extra options allowed
}
} > This means that you type "mutt -f +<TAB>" and zsh will complete files in
} > your $HOME/Mail directory following the + sign.  Mutt understands the + as
} > an abbreviation for the mail directory.  In the absence of a +, zsh just
} > completes file names after "mutt -f".
} This is exactly what I am trying to teach zsh-3.1.6.pws16 to do.

The follow only sort of accomplishes it.  I now get:

zagzig[166] mutt -f +z<TAB>
zagzig[166] mutt -f /home/schaefer/Mail/z<TAB>
/home/schaefer/Mail/zanshin           /home/schaefer/Mail/zsh-maintenance 
/home/schaefer/Mail/zsh
<BEEP>

That is, the first TAB replaces the + with the $maildirectory path, the
second TAB lists the completions.

There has to be a better way.

One thing that makes this difficult is that _path_files does not accept
the -i option of compadd, only the -P option.  However, even calling

compadd -i + -f -W ~/Mail

directly does not accomplish what I expected it to.  Is this a bug, or am
I missing something?  What IS the compadd equivalent of

compctl -x 's[+] c[-1,-f],s[-f+]' -W ~/Mail -f ...

Index: Completion/User/_mailboxes
===================================================================
@@ -38,5 +38,9 @@
   _mailbox_cache=($_mailbox_cache $mboxes $maildirboxes $MHboxes)
 fi
 
-_wanted files expl 'mailbox specification' &&
+if _wanted files expl 'mailbox specification'; then
+    local opre=$PREFIX
+    [[ $PREFIX = +* ]] && PREFIX="$~maildirectory/${PREFIX#+}"
     compadd "$@" "$expl[@]" - "$_mailbox_cache[@]"
+    PREFIX=$opre
+fi

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


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

* Re: completion but extra options allowed
@ 2000-02-14 11:56 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-02-14 11:56 UTC (permalink / raw)
  To: zsh-workers


[ moved to zsh-workers ]

Bart Schaefer wrote:

> ...
>
> Yes, I noticed just after posting that this isn't actually handled by
> _mutt and _mailboxes.  In attempting to do something with this, I found
> some rather strange things going on in the guts of the completion.
> 
> _mutt calls _arguments in the expected way.
> 
> _arguments calls "_description arguments expl mailbox" which sets expl
> to (-J -default-).
> 
> _arguments then calls "_mailboxes -J -default-" which (after setting up
> the cache) calls "_wanted files expl 'mailbox specification'" which again
> sets expl to (-J -default-).
> 
> _mailboxes then calls "compadd -J -default- -J -default- - ..." which
> seems a bit odd.  The first -J -default- is from "$@" and the second is
> of course "$expl[@]".  Is that really doing the right thing?

1) Depending of the setting of the group-name style you may have gotten
different names.
2) Yes, that's ok. The _description in _mailboxes sets up a default
description that may be overridden by a calling function.
3) Depending on the implementors preferences, he may or may not change 
the '-f+:mailbox:_mailboxes' to '-f+:mailbox: _mailboxes', which will
make _arguments *not* give a description to _mailboxes (i.e., then you 
only get the second one).


In another message:

> ...
> 
> One thing that makes this difficult is that _path_files does not accept
> the -i option of compadd, only the -P option.

All completion I can think of are written so that they work nicely
when PREFIX/IPREFIX (and SUFFIX/ISUFFIX) are set up appropriately.

> However, even calling
> 
> compadd -i + -f -W ~/Mail
> 
> directly does not accomplish what I expected it to.  Is this a bug, or am
> I missing something?  What IS the compadd equivalent of
> 
> compctl -x 's[+] c[-1,-f],s[-f+]' -W ~/Mail -f ...

-i just *adds* some string to IPREFIX. It is really only useful when
used with -U, i.e. by functions that have to do all the matching
themselves (because then IPREFIX isn't used by the completion code and 
-i can be used to tell it about an ignored prefix).

So, the right way to do the same as that compctl would be:

  if compset -P '+|-f+' || [[ $words[CURRENT-1] = -f ]]; then
    _files -W ~/Mail
  else
    ...
  fi

where the compset sets up PREFIX/IPREFIX for us.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~2000-02-14 11:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20000210153411.A27005@fruitcom.com>
     [not found] ` <1000210175857.ZM6927@candle.brasslantern.com>
     [not found]   ` <20000210195143.A26109@br-online.de>
2000-02-11 18:45     ` completion but extra options allowed Bart Schaefer
2000-02-14 11:56 Sven Wischnowsky

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