Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Qmail-Scanner-Diagnostics: from hermes.apache.org by f.primenet.com.au (envelope-from <danielsh@apache.org>, uid 7791) with qmail-scanner-2.11 
 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1.  
 Clear:RC:0(140.211.11.3):SA:0(-1.3/5.0):. 
 Processed in 0.123528 secs); 04 Aug 2016 15:53:32 -0000
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1
X-Envelope-From: danielsh@apache.org
X-Qmail-Scanner-Mime-Attachments: |
X-Qmail-Scanner-Zip-Files: |
Received-SPF: none (ns1.primenet.com.au: domain at apache.org does not designate permitted sender hosts)
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH] Make 'whence -v autoloaded-function' shows the defining filename.
Date: Thu,  4 Aug 2016 15:53:27 +0000
Message-Id: <1470326007-3112-1-git-send-email-danielsh@tarsus.local2>
X-Mailer: git-send-email 2.1.4
X-Seq: zsh-workers 38991

This may also fix a problem whereby the %x prompt escape evaluated to
a function name rather than a filename, since %x is also backed by
scriptfilename.
---
 Src/exec.c           |  3 ++-
 Test/C04funcdef.ztst | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Src/exec.c b/Src/exec.c
index 515406f..ea9214d 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4915,7 +4915,8 @@ execautofn_basic(Estate state, UNUSED(int do_exec))
 
     oldscriptname = scriptname;
     oldscriptfilename = scriptfilename;
-    scriptname = scriptfilename = dupstring(shf->node.nam);
+    scriptname = dupstring(shf->node.nam);
+    scriptfilename = dupstring(shf->filename);
     execode(shf->funcdef, 1, 0, "loadautofunc");
     scriptname = oldscriptname;
     scriptfilename = oldscriptfilename;
diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst
index 496577f..9f15e04 100644
--- a/Test/C04funcdef.ztst
+++ b/Test/C04funcdef.ztst
@@ -321,6 +321,16 @@
 >  print oops was successfully autoloaded
 >}
 
+  (
+    fpath=(.)
+    printf '%s\n' 'oops(){}' 'ninjas-earring(){}' 'oops "$@"' >oops
+    autoload oops
+    oops
+    whence -v oops
+  )
+0:whence -v of zsh-style autoload
+>oops is a shell function from ./oops
+
 %clean
 
  rm -f file.in file.out

