Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Adding a prefix to certain filename completions
- X-seq: zsh-users 9059
- From: Nikolai Weibull <mailing-lists.zsh-users@xxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Adding a prefix to certain filename completions
- Date: Fri, 8 Jul 2005 12:12:25 +0200
- In-reply-to: <1050708012444.ZM15812@xxxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050704193711.GF6330@xxxxxxxxxxxxxxxx> <20050705042324.GA21301@xxxxxxxxxxxxxxxxx> <20050705080946.GC5333@xxxxxxxxxxxxxxxx> <Pine.OSX.4.58.0507050720380.17349@xxxxxxxxxxxxxxx> <1050706050022.ZM13972@xxxxxxxxxxxxxxxxxxxxxxx> <20050706113154.GA5313@xxxxxxxxxxxxxxxx> <20050707020210.GA5084@xxxxxxxxxxxxxxxx> <1050707054007.ZM14965@xxxxxxxxxxxxxxxxxxxxxxx> <20050707105817.GA5452@xxxxxxxxxxxxxxxx> <1050708012444.ZM15812@xxxxxxxxxxxxxxxxxxxxxxx>
Bart Schaefer wrote:
> > Done. I modified the function a bit to handle files named +<n> a bit
> > better:
> I'm not sure this is better. Previously you should have seen the
> explanation of 'line number' on the first tab, and then been able to
> complete the file name on the second tab. With your change, you'll
> never see the 'line number' message, it'll always complete the file.
No, that's true. However, when I tried it, I never get to the second
group on sucessive tabs (even after an 'emulate zsh').
> But if that's the behavior you wanted, this would be a better way:
>
> _vim_files () {
> case $PREFIX in
> (+*) _files -P './' $* && return 0 ;;
> (*) _files $* ;;
> esac
> case $PREFIX in
> (+) _message -e 'start at given line (default: end of file)' ;;
> (+<->) _message -e 'line number' ;;
> esac
> }
OK, I changed it to that.
> Oh, one other thing ... having _vim_files embedded in the file named _vim
> in that way, causes _vim_files to be redefined as a function every time
> the _vim function is *called*. I should have noticed that before. See
> something like _cvs for an example of defining multiple functions in the
> same file.
Ah, I was looking for examples of completion functions using auxiliary
functions and actually saw that, but never got around to adding the
redefinition-protection. Thanks.
I've included a patch against CVS,
nikolai
--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
--- _vim 2005-07-07 14:56:46.000000000 +0200
+++ /home/pcp/.local/etc/zsh/functions/_vim 2005-07-08 12:09:19.936813032 +0200
@@ -1,16 +1,15 @@
#compdef vim exim gvim gex gview rvim rview rgvim rgview evim eview vimdiff gvimdiff
+(( $+functions[_vim_files] )) ||
_vim_files () {
- if [[ $(echo $PREFIX*(N)) == '' ]]; then
- case $PREFIX in
- (+) _message -e 'start at a given line (default: end of file)' ;;
- (+<1->) _message -e 'line number' ;;
- esac
- fi
case $PREFIX in
- (+*) _files -P './' $* ;;
+ (+*) _files -P './' $* && return 0 ;;
(*) _files $* ;;
esac
+ case $PREFIX in
+ (+) _message -e 'start at a given line (default: end of file)' ;;
+ (+<1->) _message -e 'line number' ;;
+ esac
}
local arguments
Messages sorted by:
Reverse Date,
Date,
Thread,
Author