zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: Completion for man (_man) patch to support -M
Date: Thu, 21 Oct 2010 20:29:12 +0100	[thread overview]
Message-ID: <20101021202912.6e26ce87@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20101021151504.GA24694@bsoares.omnisys.int.com.br>

On Thu, 21 Oct 2010 13:15:14 -0200
Silas Silva <silasdb@gmail.com> wrote:
> I was studying the completion system and, since I would like to add
> support for -M for the _man completion, I've done it.  Dirty and ugly
> patch is attached.

Not sure how widespread support for that argument is, certainly man is
historically rather different on different systems, but _man already
doesn't look much like other completion functions, and the intention
here is obvious enough, so I've committed it.

(For years I've wanted to make man complete files, i.e. by direct path
to the file to be read rather than via manual path + suffix, when
supported, e.g. by GNU, but never unpicked _man enough to do it.)

>     +  if (( $words[(I)-M] == (( $CURRENT - 1 )) )); then
>     +    _directories && return 0
>     +  fi
>     +
> 
> Here I wanted to check if the cursor position (where the user will hit
> tab) will be just after the -M option.  If true, it complete for
> directories and exit.  Is it right?  Is there any better way to make
> that check?

That will do fine.  There are probably other ways of doing it, but
CURRENT and words are the right variables.

>     +  if (( $words[(I)-M] )); then
>     +    local opt
>     +    opt=$words[(( $words[(I)-M]+1 ))]
>     +    _manpath=($_manpath $opt)
>     +  fi
>     +

There's actually a philosphical bug there.  You need $(( ... )) to return the
expanded value, not (( ... )).  However, I say it's a philosophical bug
because actually the contents of the [...] are evaluated as an
arithmetical expression anyway, so you can omit the parentheses --- and
when they're there, the simply do grouping as in any other arithmetic
expression, so actually what you've got works fine, slightly accidentally.

> _man sets a local MANPATH to make man look for man pages in the right
> places.  If the user set a man path with -M, I want it to be added to
> the _manpath variable.
> 
> I'm just not sure if it is the better way to do it.  opt holds the
> option passed to the -M flag, but (( $words[(I)-M]+1 )) looks ugly?

Well, apart from the obvious use of a variable (and omitting the
parentheses),

  integer ind=$words[(I)-M]
  if (( ind )); then
    local opt
    opt=$words[ind+1]
    _manpath=($_manpath $opt)
  fi

I don't see a major improvement.   (I'll commit this improvement on top.)

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2010-10-21 21:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-21 15:15 Silas Silva
2010-10-21 19:29 ` Peter Stephenson [this message]
2010-10-21 22:19   ` Silas Silva
2010-10-22 14:11   ` Greg Klanderman

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=20101021202912.6e26ce87@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@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).