zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] Add xxd completion
Date: Wed, 08 Oct 2014 16:35:07 +0200	[thread overview]
Message-ID: <30554.1412778907@thecus.kiddle.eu> (raw)
In-Reply-To: <20141008082016.GC1712@tarsus.local2>

Daniel Shahaf wrote:
> Attached completion for xxd (a hex dump utility from Vim).  It works,

Great, thanks.

> but I haven't written completion functions before so I might have
> overlooked something.

With that in mind, I've taken a look and have a couple of
recommendations.

> +local curcontext="$curcontext" ret=1 arguments

None of these are actually needed. curcontext is only relevant if you
call _arguments or _values with the -C option. You do use ret but a zsh
function will pass on the return status of the last command it calls and
_xxd only adds matches with a final call to _arguments. Finally the
arguments array is only expanded once and could be specified inline at
that point.

> +# TODO: permit two hyphens (--autoskip, --groupsize, etc)

Given that two dashes is accepted but not documented by xxd and that it
also works for the short options, e.g. --u, I would just strip a dash as
follows:

  [[ -prefix -- ]] && compset -P -

> +# TODO: xxd -<tab> should show '-x' and '-x:' differently - give visual hint that there's a required argument

Unless I'm missing something, there's nothing xxd specific in that
desire. Perhaps it should be considered for the general case. In many
cases, you can tell options that take an argument by the fact that the
description starts with the word "specify". Taking -c as an example, you
have:

> +    {-c+,-cols}'[output ARG octets per line]:number of octets per line'

Until I checked, and found otherwise, I was guessing that the "ARG" came
from a direct cut and paste from the -help output.

The arguments to -c, -g, -l and -s also get in the way of completing
-cols, -groupsize, -len and -seek:
  % xxd -grou<tab>
  number of octets per group
  option
  -groupsize

To _arguments, the rou characters could be the number of octets. By
using _guard, we can tell it that the number can only be the characters
0-9 (xxd allows hex so a few more characters are allowed there). With
_guard, it looks like this:

  {-c+,-cols}'[specify number of octets per line]: :_guard "[0-9a-fA-Fx]#" "number of octets per line"'

Oliver


  reply	other threads:[~2014-10-08 14:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-08  8:20 Daniel Shahaf
2014-10-08 14:35 ` Oliver Kiddle [this message]
2014-10-09  8:21   ` Daniel Shahaf
2014-10-11  9:46     ` [Bulk] " Oliver Kiddle
2014-10-11 16:19       ` Bart Schaefer
2014-10-18 14:08         ` Daniel Shahaf
2014-10-11 21:25       ` Daniel Shahaf

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=30554.1412778907@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /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).