From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19092 invoked by alias); 21 Oct 2010 21:11:14 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15465 Received: (qmail 2412 invoked from network); 21 Oct 2010 21:11:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.56 as permitted sender) Date: Thu, 21 Oct 2010 20:29:12 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Completion for man (_man) patch to support -M Message-ID: <20101021202912.6e26ce87@pws-pc.ntlworld.com> In-Reply-To: <20101021151504.GA24694@bsoares.omnisys.int.com.br> References: <20101021151504.GA24694@bsoares.omnisys.int.com.br> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.1 cv=DhNl2YeytwJssBBGe49HJX82LNDFEEVkpVB34RXKaPo= c=1 sm=0 a=FK_7cdtOvw8A:10 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=NLZqzBF-AAAA:8 a=Vm8anIHTtextMfpK_VAA:9 a=y1mGQJQDLAwmgxwi9vcA:7 a=ZIdghJ4S4p5BYEGLRgoKKHSLl2sA:4 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 a=_dQi-Dcv4p4A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Thu, 21 Oct 2010 13:15:14 -0200 Silas Silva 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/