zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: whence and the location of a function definition
Date: Wed, 15 Apr 2015 22:24:01 -0700	[thread overview]
Message-ID: <150415222401.ZM28699@torch.brasslantern.com> (raw)
In-Reply-To: <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;
     }
  


      reply	other threads:[~2015-04-16  5:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAGfENy_hFQro9greE7-DRXOw3UQG7Qkp6RPbnkpJFq39Den_5A@mail.gmail.com>
     [not found] ` <CAHYJk3TWJVsWCTO0xJ-iw2ThBAdbrvs2Pfc6-t6aqj1yBQ-djA@mail.gmail.com>
2015-04-06 16:43   ` Bart Schaefer
2015-04-10  0:43     ` Mikael Magnusson
2015-04-16  5:24       ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150415222401.ZM28699@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).