From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2121 invoked by alias); 16 Apr 2015 05:24:13 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34903 Received: (qmail 22059 invoked from network); 16 Apr 2015 05:24:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) 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 autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=YTJgXTq3PikX/MZGeEIt6yCvLnGmsTDVxD1t9x1eT9Y=; b=CnG1IBp0CFvdkTjZUeqwE6ECrwbHUTzBGwPHa44FvRFFC7psL8Q9Lbz5ESyLaFPyhn daMOF7yj1NetcdH7xHDCj4RP/zlvpNz3L7ghVQK82FMrukQhjcOliPLW1CSFdvSvpm9h Zx6ipPNFQF1hZH80utDVHgHHRknjdzES5xm0TYYoqnMch6+xYQtgZHXkr5bQ4AuEXnZP AFpbzZ2BZksbT9cNXXVdrhvEh9FTs2qTPlmWv+HKZK7LmN074MylJH7l7eONYohpt6u4 1SS7e+1ux5jqGhE3wUFgGhnXCSfgp7xvBqf+Ea2gHvifXCmFpUmK/dsH6uyTeakkaNwz PH+w== X-Gm-Message-State: ALoCoQmNg6gpB36ZXDD1D2A+aqTv9HBMAIx4qki1DdmByyDQKFv2YX1ojJpbpANId/xzCcE885RI X-Received: by 10.202.81.207 with SMTP id f198mr18683910oib.126.1429161844595; Wed, 15 Apr 2015 22:24:04 -0700 (PDT) From: Bart Schaefer Message-Id: <150415222401.ZM28699@torch.brasslantern.com> Date: Wed, 15 Apr 2015 22:24:01 -0700 In-Reply-To: Comments: In reply to Mikael Magnusson "Re: whence and the location of a function definition" (Apr 10, 2:43am) References: <150406094325.ZM20639@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh workers Subject: Re: whence and the location of a function definition MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Apr 10, 2:43am, Mikael Magnusson wrote: } Subject: Re: whence and the location of a function definition } } > } http://git.mikachu.zsh.jp/commit/?h=mika&id=225140c2aa029c9f19615c5894c4813a88afca49 } > } and then run whence -F thefunc } > } > This looks useful, especially if the "(unknown)" branch could report } > whether the function is autoloaded. } > } > Any opinions on whether it needs its own option, or if it could always be } > appended to the "-v" output, e.g. } } Those both sound like good ideas to me OK, this turns out not to be as useful as it first appears. The file name available in the Shfunc node is almost never a full path. For autoloaded functions, it's just the base name of the file; it has a path only for functions from source'd files (including .zshrc, et al.) and those that were forced to load via "autoload +X" (very rare). So ... rather than produce meaningless output like torch% whence -v _git _git is a shell function from _git I've elected to go with torch% whence -v _git _git is a shell function torch% whence -v _git_commands _git_commands is a shell function from _git I'm undecided about whether the file name should be output using nicezputs(). On the one hand, the function name is output that way, so we've already lost some ability to machine-read this output. On the other hand, one might be more likely to want the un-beautified file name. Incidentally "whence -m" is basically useless for aliases unless one of -w or -v is also given, because -m prints only the expansion of the alias and not the pattern-matched name. Sadly the various print*node functions in hashtable.c are not consistent about which of the PRINT_* flags take precedence, so it's convoluted to e.g. get aliases to print in name=expansion format when other hashes must print just the name. The patch below therefore does not change the handling of aliases. diff --git a/Src/hashtable.c b/Src/hashtable.c index 7a43062..b8cb563 100644 --- a/Src/hashtable.c +++ b/Src/hashtable.c @@ -910,7 +910,7 @@ printshfuncnode(HashNode hn, int printflags) { Shfunc f = (Shfunc) hn; char *t = 0; - + if ((printflags & PRINT_NAMEONLY) || ((printflags & PRINT_WHENCE_SIMPLE) && !(printflags & PRINT_WHENCE_FUNCDEF))) { @@ -922,8 +922,16 @@ printshfuncnode(HashNode hn, int printflags) if ((printflags & (PRINT_WHENCE_VERBOSE|PRINT_WHENCE_WORD)) && !(printflags & PRINT_WHENCE_FUNCDEF)) { nicezputs(f->node.nam, stdout); - printf((printflags & PRINT_WHENCE_WORD) ? ": function\n" : - " is a shell function\n"); + printf((printflags & PRINT_WHENCE_WORD) ? ": function" : + (f->node.flags & PM_UNDEFINED) ? + " is an autoload shell function" : + " is a shell function"); + if (f->filename && (printflags & PRINT_WHENCE_VERBOSE) && + strcmp(f->filename, f->node.nam) != 0) { + printf(" from "); + zputs(f->filename, stdout); + } + putchar('\n'); return; }