zsh-workers
 help / color / mirror / code / Atom feed
* whence and the location of a function definition
       [not found] ` <CAHYJk3TWJVsWCTO0xJ-iw2ThBAdbrvs2Pfc6-t6aqj1yBQ-djA@mail.gmail.com>
@ 2015-04-06 16:43   ` Bart Schaefer
  2015-04-10  0:43     ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-04-06 16:43 UTC (permalink / raw)
  To: zsh-workers

On Apr 6,  6:57am, Mikael Magnusson wrote:
}
} another way is to apply this patch:
} 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.

compdef is a shell function from /usr/share/zsh/functions/Completion/compinit


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: whence and the location of a function definition
  2015-04-06 16:43   ` whence and the location of a function definition Bart Schaefer
@ 2015-04-10  0:43     ` Mikael Magnusson
  2015-04-16  5:24       ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2015-04-10  0:43 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh workers

On Mon, Apr 6, 2015 at 6:43 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Apr 6,  6:57am, Mikael Magnusson wrote:
> }
> } another way is to apply this patch:
> } 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.
>
> compdef is a shell function from /usr/share/zsh/functions/Completion/compinit

Those both sound like good ideas to me (I'm not the original author of
the patch). :)

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: whence and the location of a function definition
  2015-04-10  0:43     ` Mikael Magnusson
@ 2015-04-16  5:24       ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2015-04-16  5:24 UTC (permalink / raw)
  To: zsh workers

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;
     }
  


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-16  5:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAGfENy_hFQro9greE7-DRXOw3UQG7Qkp6RPbnkpJFq39Den_5A@mail.gmail.com>
     [not found] ` <CAHYJk3TWJVsWCTO0xJ-iw2ThBAdbrvs2Pfc6-t6aqj1yBQ-djA@mail.gmail.com>
2015-04-06 16:43   ` whence and the location of a function definition Bart Schaefer
2015-04-10  0:43     ` Mikael Magnusson
2015-04-16  5:24       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).