From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8803 invoked by alias); 25 Nov 2010 15:33:05 -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: 15580 Received: (qmail 24642 invoked from network); 25 Nov 2010 15:33:02 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Thu, 25 Nov 2010 15:32:50 +0000 From: Peter Stephenson To: zsh-users Subject: Re: todo.sh completion Message-ID: <20101125153250.703e1239@pwslap01u.europe.root.pri> In-Reply-To: References: <20101125134534.58a6e784@pwslap01u.europe.root.pri> <87lj4h4ieq.fsf@ft.bewatermyfriend.org> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 25 Nov 2010 15:32:51.0109 (UTC) FILETIME=[054D7550:01CB8CB6] X-Scanned-By: MailControl A_10_80_00 (www.mailcontrol.com) on 10.68.0.120 On Thu, 25 Nov 2010 15:34:56 +0100 Julien Nicoulaud wrote: > OK, I checked my zshrc and it turns out this was breaking the > completion script: > > autoload -U zsh-mime-setup && zsh-mime-setup Useful research, thank you. > I guess this has to do with todo.sh ending with ".sh", since every > others completion scripts work fine. Yes, what should happen is that _zsh-mime-handler finds it shouldn't be handling todo.sh in this case and despatching to normal completion instead. There were some (at least three) glitches with this. This fixes the ones I found. - zsh-mime-handler didn't handle the "-l" option for stuff it passed through without handling. (This should simply end up with $words being pruned from the front.) - _zsh-mime-handler didn't keep empty arguments, which is what you get when you first try completion on a word. - _zsh-mime-handler updated $words but didn't update $CURRENT. Best guess is to keep $CURRENT at the same offset from the end of $words. Index: Completion/Zsh/Function/_zsh-mime-handler =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Function/_zsh-mime-handler,v retrieving revision 1.1 diff -p -u -r1.1 _zsh-mime-handler --- Completion/Zsh/Function/_zsh-mime-handler 23 May 2010 19:54:03 -0000 1.1 +++ Completion/Zsh/Function/_zsh-mime-handler 25 Nov 2010 15:29:27 -0000 @@ -1,9 +1,19 @@ #compdef zsh-mime-handler +# Given that the handler is likely to change the start of the command +# line, we'll try to maintain the position from the end of the words +# array. Hence for example CURRENT gets decremented by one if the +# handler drops off the start. +integer end_offset=$(( ${#words} - CURRENT )) + # zsh-mime-handler -l is supposed to print out the command line # with quoting to turn it into a full executable line. So # we need to use shell splitting to turn it into words and # then unquoting on those words. -words=(${(Q)${(z)"$(zsh-mime-handler -l ${words[2,-1]})"}}) +words=(${(z)"$(zsh-mime-handler -l "${(@)words[2,-1]}")"}) +# Careful unquoting: we need to keep a '' as a separate word. +words=("${(@Q)words}") + +(( CURRENT = ${#words} - end_offset )) _normal Index: Functions/MIME/zsh-mime-handler =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-handler,v retrieving revision 1.13 diff -p -u -r1.13 zsh-mime-handler --- Functions/MIME/zsh-mime-handler 8 Aug 2010 17:20:55 -0000 1.13 +++ Functions/MIME/zsh-mime-handler 25 Nov 2010 15:29:27 -0000 @@ -144,7 +144,11 @@ if [[ ! -e $1 ]]; then fi done if [[ -z $nonex_ok ]]; then - "$@" + if (( list )); then + print -r -- "${(q)@}" + else + "$@" + fi return fi fi -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom