From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1151 invoked from network); 27 Mar 2008 11:25:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 27 Mar 2008 11:25:30 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 62585 invoked from network); 27 Mar 2008 11:25:25 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Mar 2008 11:25:25 -0000 Received: (qmail 4988 invoked by alias); 27 Mar 2008 11:25:23 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24759 Received: (qmail 4972 invoked from network); 27 Mar 2008 11:25:22 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 27 Mar 2008 11:25:22 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [217.69.20.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 6B6F182CD267 for ; Thu, 27 Mar 2008 12:25:16 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly41d.srv.mailcontrol.com (MailControl) with ESMTP id m2RBOh9J031527 for ; Thu, 27 Mar 2008 11:25:15 GMT Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Thu, 27 Mar 2008 11:25:06 +0000 Date: Thu, 27 Mar 2008 11:25:06 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: _canonical_path not working on *BSD Message-ID: <20080327112506.7298e9ef@news01> In-Reply-To: <20080327120807.415095ee@raveland.org> References: <20080326114413.80713vrmznwpnyuc@bapt.selfip.org> <080326083638.ZM16858@torch.brasslantern.com> <200803261540.m2QFeJmm017381@news01.csr.com> <200803261604.m2QG41Ke017772@news01.csr.com> <200803261621.m2QGLptV017966@news01.csr.com> <20080326173824.0a55c00d@coredump.raveland.priv> <20080326164615.1d5893ed@news01> <20080327102325.55808716@news01> <20080327120807.415095ee@raveland.org> Organization: CSR X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.5; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 27 Mar 2008 11:25:06.0374 (UTC) FILETIME=[354C2660:01C88FFD] X-Scanned-By: MailControl A-08-00-04 (www.mailcontrol.com) on 10.68.0.151 X-Virus-Scanned: ClamAV 0.91.2/6421/Thu Mar 27 09:54:20 2008 on bifrost X-Virus-Status: Clean On Thu, 27 Mar 2008 12:08:07 +0100 Pea wrote: > [pea@pea-dsktp:~]% umount _canonical_paths_get_canonical_path:unfunction:1: no such hash table element: chpwd > _canonical_paths_get_canonical_path:unfunction:1: no such hash table element: chpwd I thought unfunction was silent if a function didn't exist, as is now true of (and required for) unset, but apparently not. Since I can't seem to get away from this, I've rewritten the function more canonically so that the helper functions only get loaded once and aren't buried in the body of the main function that gets stored. Most of the patch is consequent rearrangement. Index: Completion/Unix/Type/_canonical_paths =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_canonical_paths,v retrieving revision 1.3 diff -u -r1.3 _canonical_paths --- Completion/Unix/Type/_canonical_paths 27 Mar 2008 10:35:21 -0000 1.3 +++ Completion/Unix/Type/_canonical_paths 27 Mar 2008 11:20:34 -0000 @@ -13,27 +13,13 @@ # case they are already so. `tag' and `desc' arguments are well, obvious :) In # addition, the options -M, -J, -V, -1, -2, -n, -F, -X are passed to compadd. -local __index -typeset -a __gopts __opts - -zparseopts -D -a __gopts M: J: V: 1 2 n F: X: A:=__opts N=__opts - -: ${1:=canonical-paths} ${2:=path} - -__index=$__opts[(I)-A] -(( $__index )) && set -- $@ ${(P)__opts[__index+1]} - -local expl ret=1 tag=$1 desc=$2 - -shift 2 - -if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then - _wanted "$tag" expl "$desc" compadd $__gopts $@ && ret=0 - return ret -fi - -typeset REPLY -typeset -a matches files +_canonical_paths_pwd() { + # Get the canonical directory name by changing to it. + # To be run in a subshell. + (( ${+functions[chpwd]} )) && unfunction chpwd + setopt CHASE_LINKS + cd $1 2>/dev/null && pwd +} _canonical_paths_get_canonical_path() { typeset newfile dir @@ -55,34 +41,20 @@ # Canonicalise the directory path. We may not be able to # do this if we can't read all components. if [[ -d $REPLY ]]; then - dir="$(unfunction chpwd - setopt CHASE_LINKS - cd $REPLY 2>/dev/null && pwd)" + dir="$(_canonical_paths_pwd $REPLY)" if [[ -n $dir ]]; then REPLY=$dir fi elif [[ $REPLY = */*[^/] && $REPLY != /[^/]# ]]; then # Don't try this if there's a trailing slash or we're in # the root directory. - dir="$(unfunction chpwd - setopt CHASE_LINKS - cd ${REPLY%/*} 2>/dev/null && pwd)" + dir="$(_canonical_paths_pwd ${REPLY%/*})" if [[ -n $dir ]]; then REPLY=$dir/${REPLY##*/} fi fi } - -if (( $__opts[(I)-N] )); then - files=($@) -else - for __index in $@; do - _canonical_paths_get_canonical_path $__index - files+=($REPLY) - done -fi - _canonical_paths_add_paths () { local origpref=$1 expref rltrim curpref canpref subdir [[ $2 != add ]] && matches=() @@ -104,35 +76,70 @@ done } -local base=$PREFIX -typeset -i blimit +_canonical_paths() { + local __index + typeset -a __gopts __opts + + zparseopts -D -a __gopts M: J: V: 1 2 n F: X: A:=__opts N=__opts + + : ${1:=canonical-paths} ${2:=path} + + __index=$__opts[(I)-A] + (( $__index )) && set -- $@ ${(P)__opts[__index+1]} -_canonical_paths_add_paths $base + local expl ret=1 tag=$1 desc=$2 -if [[ -z $base ]]; then - _canonical_paths_add_paths / add -elif [[ $base == ..(/.(|.))#(|/) ]]; then - - # This style controls how many parent directory links (..) to chase searching - # for possible completions. The default is 8. Note that this chasing is - # triggered only when the user enters atleast a .. and the path completed - # contains only . or .. components. A value of 0 turns off .. link chasing - # altogether. - - zstyle -s ":completion:${curcontext}:$tag" \ - canonical-paths-back-limit blimit || blimit=8 - - if [[ $base != */ ]]; then - [[ $base != *.. ]] && base+=. - base+=/ + shift 2 + + if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then + _wanted "$tag" expl "$desc" compadd $__gopts $@ && ret=0 + return ret fi - until [[ $base.. -ef $base || blimit -le 0 ]]; do - base+=../ - _canonical_paths_add_paths $base add - blimit+=-1 - done -fi -_wanted "$tag" expl "$desc" compadd $__gopts -Q -U -a matches && ret=0 + typeset REPLY + typeset -a matches files + + if (( $__opts[(I)-N] )); then + files=($@) + else + for __index in $@; do + _canonical_paths_get_canonical_path $__index + files+=($REPLY) + done + fi + + local base=$PREFIX + typeset -i blimit + + _canonical_paths_add_paths $base + + if [[ -z $base ]]; then + _canonical_paths_add_paths / add + elif [[ $base == ..(/.(|.))#(|/) ]]; then + + # This style controls how many parent directory links (..) to chase searching + # for possible completions. The default is 8. Note that this chasing is + # triggered only when the user enters atleast a .. and the path completed + # contains only . or .. components. A value of 0 turns off .. link chasing + # altogether. + + zstyle -s ":completion:${curcontext}:$tag" \ + canonical-paths-back-limit blimit || blimit=8 + + if [[ $base != */ ]]; then + [[ $base != *.. ]] && base+=. + base+=/ + fi + until [[ $base.. -ef $base || blimit -le 0 ]]; do + base+=../ + _canonical_paths_add_paths $base add + blimit+=-1 + done + fi + + _wanted "$tag" expl "$desc" compadd $__gopts -Q -U -a matches && ret=0 + + return ret +} -return ret +_canonical_paths "$@" -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070