From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29681 invoked from network); 8 Jul 2006 11:45:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Jul 2006 11:45:26 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 34923 invoked from network); 8 Jul 2006 11:45:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Jul 2006 11:45:16 -0000 Received: (qmail 23715 invoked by alias); 8 Jul 2006 11:45:08 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10495 Received: (qmail 23705 invoked from network); 8 Jul 2006 11:45:08 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Jul 2006 11:45:08 -0000 Received: (qmail 33929 invoked from network); 8 Jul 2006 11:45:08 -0000 Received: from mta09-winn.ispmail.ntl.com (HELO mtaout03-winn.ispmail.ntl.com) (81.103.221.49) by a.mx.sunsite.dk with SMTP; 8 Jul 2006 11:45:06 -0000 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com with ESMTP id <20060708114504.PQIT1865.mtaout03-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Sat, 8 Jul 2006 12:45:04 +0100 Received: from pwslaptop.csr.com ([81.107.41.155]) by aamtaout03-winn.ispmail.ntl.com with ESMTP id <20060708114504.LZKI18889.aamtaout03-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Sat, 8 Jul 2006 12:45:04 +0100 Received: from pwslaptop.csr.com (pwslaptop.csr.com [127.0.0.1]) by pwslaptop.csr.com (8.13.6/8.13.4) with ESMTP id k68BiwEY023823 for ; Sat, 8 Jul 2006 12:45:00 +0100 Message-Id: <200607081145.k68BiwEY023823@pwslaptop.csr.com> From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: Redirection Symbol After Completion In-Reply-To: Your message of "Fri, 07 Jul 2006 13:32:13 EDT." <20060707173213.GA22592@namib.cs.utk.edu> Date: Sat, 08 Jul 2006 12:44:58 +0100 Chris Johnson wrote: > Hi. This is just a minor, cosmetic nuance of zsh that I'd like to > change, if possible. When I complete a filename with > > cat fil > > the command line becomes "cat file.txt ". A space is displayed after > the completed filename, though I didn't type it. If I type another > argument, the space remains and separates the arguments. However, if I > type a redirection character like & or |, the space is removed and I get > > cat file.txt| > > I personally find commands easier to parse with my eye when the space > remains before the redirection symbol: > > cat file.txt | > > Is there any way to force this space to persist even if I type a > redirection operator? Thanks for any insight. It's a perfectly reasonable thing to want to configure, but unfortunately I don't think it's possible to do this without some tweaking of the completion system. Even then, it's quite tricky to get right and I haven't managed to so far. To illustrate, here is a partial answer. With the patch below you can set, say, zstyle ":completion::complete:*:all-files" remove-chars " \t\n;&" to change the set of characters which, when typed, will cause suffix removal for the "all-files" tag (the general catch-all file completion); it's the usual set with "|" removed. (You'd probably want it more generally, but as we'll see that's problematic.) At first sight this does what you want. However, try this mkdir testdir echo test giving echo testdir/ and now type "|". The slash isn't removed, as it usually would be. That's because the same mechanism controls the characters removed when you have a suffix, including an automatically added /, and when you don't, i.e. you get the space in your original question. (The rest of this description is for connoisseurs...) It gets even more complicated when a function specifies its own suffix removal. This again conflicts with with what I've done: I added the test for the style to _description, which prepares options for the builtin compadd that passes the details to the shell's internals for handling. Unfortunately _description not only doesn't know what the suffix is, it doesn't know whether someone else might have used the -r option. For example when completing values for PATH the -r option is passed down to indicate that ":" should cause a space to be removed. _description doesn't see this and _path_files (the core of file completion) sees two incompatible -r options and, as luck would have it, uses the wrong one. To complicate matters even further, sometimes _path_files will call _description itself while at other times (as in this case) it's already been called. Probably this can be done better but it needs some clear thinking. I won't commit this patch. The easiest thing to do is to add two options to compadd: one to specify the default characters when there's a suffix, one to specify it when there isn't. These would both be overridden by -r. However, that seems a rather feeble alternative to getting the logic in the functions right. Index: Completion/Base/Core/_description =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_description,v retrieving revision 1.5 diff -u -r1.5 _description --- Completion/Base/Core/_description 21 Jul 2003 17:01:44 -0000 1.5 +++ Completion/Base/Core/_description 8 Jul 2006 11:16:31 -0000 @@ -1,12 +1,10 @@ #autoload -local name gropt nopt xopt format gname hidden hide match opts tag sort - -opts=() +local name gropt xopt format gname hidden hide match tag sort remchars +local -a opts nopt gropt=(-J) xopt=(-X) -nopt=() zparseopts -K -D -a nopt 1 2 V=gropt J=gropt x=xopt 3="${${3##[[:blank:]]#}%%[[:blank:]]#}" @@ -31,6 +29,9 @@ opts=($opts -M "$match") [[ -n "$_matcher" ]] && opts=($opts -M "$_matcher") +zstyle -s ":completion:${curcontext}:$1" remove-chars remchars && + opts=($opts -r $remchars) + # Use sort style, but ignore `menu' value to help _expand. # Also don't override explicit use of -V. if { zstyle -s ":completion:${curcontext}:$1" sort sort || -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/