zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: John Beppu <beppu@ax9.org>
Cc: zsh-workers <zsh-workers@sunsite.auc.dk>
Subject: Re: A Completion Function for FIGlet
Date: Wed, 20 Mar 2002 12:13:14 +0000	[thread overview]
Message-ID: <20020320121314.GA7589@logica.com> (raw)
In-Reply-To: <20020320091931.GA29379@Ax9.org>

John Beppu wrote:

> The attached file contains a completion function for figlet[1] that I just
> finished writing, and I would like to donate it to the zsh distribution.

Great. Thanks.

> I don't think I've done anything terrible, but then again, this is 
> my first completion function, so it wouldn't be surprising if I made
> a few mistakes.  If there's anything wrong w/ it, please let me know.

It looks good. I can't see much which is as such wrong.

> I also have a few questions:
> 
>   regarding $opt_args
>     Is it only set when you use the '->state' mechanism?
>     It seems to be empty, otherwise.

No. It is set by the call to _arguments which is probably later than
you wanted. In this case, you can do the following though:

  '-f+[font]:font:_files -W ${~opt_args[-d]\:-$fontdir} -g \*flf\*' \
  '-C+[control file]:control file:_files -W ${~opt_args[-d]\:-$fontdir} -g \*flc\*' \

_arguments will evaluate the reference to opt_args before calling
_files so it works.

>   arguments to _arguments
>     The following is a line from the completion function:
> 
>         "-d+[directory]:directory:_path_files -/" \
>                         ^^^^^^^^^
> 
>     What is the purpose of the underlined string?
>     When might this string be useful to someone who is
>     writing completion functions?  Is their a proper name
>     for the strings that go there?

It is a description which is displayed as a heading above those
matches. _path_files will set a default heading which this one
overrides. The heading is only displayed if you have a format style
with the descriptions tag (see below).

> PS: I'm going to use this as the basis for a little article on writing
>     completion functions.  I still need to improve my understanding of
>     how this all works, though.  Zsh is so complicated...  My head
>     hurts from RTFM.

If the article is to be published on the web let me know and I'll add a
link from the zsh web pages. Have you read Peter's user guide in
addition to the manual? 

>     Many times, I've wished for a tool like perldoc.  It could be called
>     zdoc, and you'd be able to do things like:

Because zsh displays quite a lot of descriptions with completions, I
quite often press tab for just such information. Have you set up your
styles to display all the information. I use:
  zstyle ':completion:*' verbose yes
  zstyle ':completion:*:descriptions' format '%B%d%b'
  zstyle ':completion:*:messages' format '%d'
  zstyle ':completion:*:warnings' format 'No matches for: %d'
  zstyle ':completion:*' group-name ''

The zdoc you describe would probably need to be integrated with the
documentation so if we ever reorganise that (such as because of Yodl
now seemingly being unmaintained) it'll be worth considering.

> _figlet() {

You don't need to write the function bit with zsh's autoloaded functions.

>  fontdir=$(figlet -I2)

I suppose this should be
   fontdir=$(_call_program path figlet -I2 2>/dev/null)
which allows a style to override the command which is called and
doesn't print an error if figlet isn't installed.

>   local context state line

>   _arguments -C -s \

If you use -C, you should use curcontext="$curcontext" in the local
line. context is an array and it is used in cases such as where more
than one state can be entered, each with a different context. In
practise such situations are fairly rare.

For _figlet, once the states are removed the -C option won't be needed.

>     "-c[center justify]" \
>     "-k[use kerning]" \
>     "-l[left justify]" \

where you have options which are mutually exlusive, you can prevent the second
from being completed after the first.
e.g.
    "(-c -r)-l[left justify]" \
prevents the -r and -c options being completed once -l has already been
specified on the line.

>     "-C+[control file]:->change_controlfile" \

You're missing the description in the spec. I've fixed it in the
replacement above.

>     "-I+[info]:info:compadd 0 1 2 3 4" \

This can be:
  "-I+[info]:info:(0 1 2 3 4)" \
  
You can also give descriptions for each of the possible values so we
can even do:
  "-I+[display info]:info:((0\:version\ and\ copyright 1\:version\ \(integer\) 2\:default\ font\ directory 3\:font 4\:output\ width))" \

I hope that helps

Oliver
-- 

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


  reply	other threads:[~2002-03-20 12:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-20  9:19 John Beppu
2002-03-20 12:13 ` Oliver Kiddle [this message]
2002-03-20 22:55   ` John Beppu
2002-03-20 17:01 ` zdoc (Re: A Completion Function for FIGlet) Bart Schaefer
2002-03-20 22:57   ` John Beppu
2002-03-24 21:15 A Completion Function for FIGlet Felix Rosencrantz

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=20020320121314.GA7589@logica.com \
    --to=okiddle@yahoo.co.uk \
    --cc=beppu@ax9.org \
    --cc=zsh-workers@sunsite.auc.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).