Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: whence and the location of a function definition
- X-seq: zsh-workers 34903
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: whence and the location of a function definition
- Date: Wed, 15 Apr 2015 22:24:01 -0700
- In-reply-to: <CAHYJk3SnMzgPQWdL=5AOGQ4YY5iOWbS048hhHhSFWSoy6aGixA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAGfENy_hFQro9greE7-DRXOw3UQG7Qkp6RPbnkpJFq39Den_5A@mail.gmail.com> <CAHYJk3TWJVsWCTO0xJ-iw2ThBAdbrvs2Pfc6-t6aqj1yBQ-djA@mail.gmail.com> <150406094325.ZM20639@torch.brasslantern.com> <CAHYJk3SnMzgPQWdL=5AOGQ4YY5iOWbS048hhHhSFWSoy6aGixA@mail.gmail.com>
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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author