zsh-workers
 help / color / mirror / code / Atom feed
* "whence -v" and function file names
@ 2015-04-25 19:51 Bart Schaefer
  2015-05-17 20:52 ` Daniel Hahler
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2015-04-25 19:51 UTC (permalink / raw)
  To: zsh-workers

In workers/34903 I posted a patch to append the function filename (when
useful) to the "whence -v" output for functions.  I temporized:

> I'm undecided about whether the file name should be output using
> nicezputs().

I settled on using quotedzputs(), which will make the filename both human
readable and copy-paste-able.


diff --git a/Src/hashtable.c b/Src/hashtable.c
index 7a43062..ab381cc 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 ");
+	    quotedzputs(f->filename, stdout);
+	}
+	putchar('\n');
 	return;
     }
  


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

* Re: "whence -v" and function file names
  2015-04-25 19:51 "whence -v" and function file names Bart Schaefer
@ 2015-05-17 20:52 ` Daniel Hahler
  2015-05-18  1:44   ` Bart Schaefer
  2015-05-18  2:31   ` Mikael Magnusson
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Hahler @ 2015-05-17 20:52 UTC (permalink / raw)
  To: zsh-workers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 25.04.2015 21:51, Bart Schaefer wrote:

> In workers/34903 I posted a patch to append the function filename (when
> useful) to the "whence -v" output for functions.  I temporized:
> 
>> I'm undecided about whether the file name should be output using
>> nicezputs().
> 
> I settled on using quotedzputs(), which will make the filename both human
> readable and copy-paste-able.
> 
> 
> diff --git a/Src/hashtable.c b/Src/hashtable.c
> index 7a43062..ab381cc 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 ");
> +	    quotedzputs(f->filename, stdout);
> +	}
> +	putchar('\n');
>  	return;
>      }


This is a nice addition, but it does not seem to work with compdef functions:

% whence -v _git
_git is an autoload shell function
% git <tab>
% whence -v _git
_git is a shell function

It would be nice if it could provide the path, at least with the second call.


Regards,
Daniel.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iD8DBQFVWP+FfAK/hT/mPgARAkdFAJ0TOGJ94lvSqB8ZzjfLsEugtqqXVACg/D2d
XZXu7fvUteUHBjp9sjxtl6o=
=AWLV
-----END PGP SIGNATURE-----


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

* Re: "whence -v" and function file names
  2015-05-17 20:52 ` Daniel Hahler
@ 2015-05-18  1:44   ` Bart Schaefer
  2015-05-18  2:31   ` Mikael Magnusson
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-05-18  1:44 UTC (permalink / raw)
  To: zsh-workers

On May 17, 10:52pm, Daniel Hahler wrote:
} Subject: Re: "whence -v" and function file names
}
} % whence -v _git
} _git is an autoload shell function
} % git <tab>
} % whence -v _git
} _git is a shell function
} 
} It would be nice if it could provide the path, at least with the second call.

Yes, that would be nice, but the code that loads the function definition
does not record the path and I didn't see any simple way to cause it to
do so.  I wasn't in this to rewrite autoloading, so you get what's there
at the time "whence" is invoked.


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

* Re: "whence -v" and function file names
  2015-05-17 20:52 ` Daniel Hahler
  2015-05-18  1:44   ` Bart Schaefer
@ 2015-05-18  2:31   ` Mikael Magnusson
  1 sibling, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2015-05-18  2:31 UTC (permalink / raw)
  To: Daniel Hahler; +Cc: zsh workers

On Sun, May 17, 2015 at 10:52 PM, Daniel Hahler
<genml+zsh-workers@thequod.de> wrote:
> On 25.04.2015 21:51, Bart Schaefer wrote:
>
>> In workers/34903 I posted a patch to append the function filename (when
>> useful) to the "whence -v" output for functions.  I temporized:
>>
>
> This is a nice addition, but it does not seem to work with compdef functions:
>
> % whence -v _git
> _git is an autoload shell function
> % git <tab>
> % whence -v _git
> _git is a shell function
>
> It would be nice if it could provide the path, at least with the second call.

It's not autoloaded or compdef functions that don't work;
% whence -v _zattr
_zattr is a shell function from
/usr/local/share/zsh/5.0.7-dev-2/functions.zwc/_zattr

but rather, things that redefine themselves from within the function
definition when run that don't;
% grep '^_git()' **/_git
_git() {

% cat foo.z

bar() {}
baz() {baz() {}; baz}

% source foo.z
% whence -v bar baz
bar is a shell function from foo.z
baz is a shell function from foo.z
% bar; baz
% whence -v bar baz
bar is a shell function from foo.z
baz is a shell function

-- 
Mikael Magnusson


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

end of thread, other threads:[~2015-05-18  2:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-25 19:51 "whence -v" and function file names Bart Schaefer
2015-05-17 20:52 ` Daniel Hahler
2015-05-18  1:44   ` Bart Schaefer
2015-05-18  2:31   ` Mikael Magnusson

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).