zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: PATCH: autoload with explicit path
Date: Tue, 17 Jan 2017 18:36:06 +0000	[thread overview]
Message-ID: <20170117183606.5d1db3de@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20170110193102.7725620a@ntlworld.com>

Currently,

autoload /path/to/foo
autoload foo

leaves foo marked as to be loaded from /path/to/foo.  I should probably
document this (and that therefore to unmark the path you need to
unfunction).  I think this is the right way of doing it as the explicit
path should continue to override the more vague autoload with no path
indicated, and this is safer in case some code decides it needs a
function and inadvertently resets the path the user carefully decided to
give the function.

However, you could argue that "autoload foo" should reset foo to reload
from $fpath, as the shell would do if it encountered that command on its
own.

You can in any case change an explicitly marked path seamlessly by
issuing a new command with an absolute path.

I have found a bug, though: "autoload /path/to/foo" takes effect
even if foo is already loaded, which isn't supposed to happen.
Test for this tomorrow.

Second hunk is a minor efficiency change: I noticed findcmd() with
second argument 1 returns a dupstring() value anyway.

pws

diff --git a/Src/builtin.c b/Src/builtin.c
index b1b6e2e..7a04a79 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3369,6 +3369,31 @@ bin_functions(char *name, char **argv, Options ops, int func)
 		removetrapnode(signum);
 	    }
 
+	    if (**argv == '/') {
+		char *base = strrchr(*argv, '/') + 1;
+		if (*base &&
+		    (shf = (Shfunc) shfunctab->getnode(shfunctab, base))) {
+		    char *dir;
+		    /* turn on/off the given flags */
+		    shf->node.flags =
+			(shf->node.flags | (on & ~PM_UNDEFINED)) & ~off;
+		    if (shf->node.flags & PM_UNDEFINED) {
+			/* update path if not yet loaded */
+			if (base == *argv + 1)
+			    dir = "/";
+			else {
+			    dir = *argv;
+			    base[-1] = '\0';
+			}
+			dircache_set(&shf->filename, NULL);
+			dircache_set(&shf->filename, dir);
+		    }
+		    if (check_autoload(shf, shf->node.nam, ops, func))
+			returnval = 1;
+		    continue;
+		}
+	    }
+
 	    /* Add a new undefined (autoloaded) function to the *
 	     * hash table with the corresponding flags set.     */
 	    shf = (Shfunc) zshcalloc(sizeof *shf);
diff --git a/Src/subst.c b/Src/subst.c
index 737a0a9..670f3f0 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -622,7 +622,7 @@ filesub(char **namptr, int assign)
 char *
 equalsubstr(char *str, int assign, int nomatch)
 {
-    char *pp, *cnam, *cmdstr, *ret;
+    char *pp, *cnam, *cmdstr;
 
     for (pp = str; !isend2(*pp); pp++)
 	;
@@ -634,10 +634,10 @@ equalsubstr(char *str, int assign, int nomatch)
 	    zerr("%s not found", cmdstr);
 	return NULL;
     }
-    ret = dupstring(cnam);
     if (*pp)
-	ret = dyncat(ret, pp);
-    return ret;
+	return dyncat(cnam, pp);
+    else
+	return cnam;		/* already duplicated */
 }
 
 /**/


  parent reply	other threads:[~2017-01-17 18:36 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-11 22:18 PATH: " Peter Stephenson
2016-12-12 16:05 ` Bart Schaefer
2016-12-12 16:31   ` Peter Stephenson
2016-12-12 18:09     ` Bart Schaefer
2017-01-10 19:31     ` Peter Stephenson
2017-01-11 11:42       ` Peter Stephenson
2017-01-11 20:51         ` Peter Stephenson
2017-01-12 20:42           ` Peter Stephenson
2017-01-13 18:04           ` Peter Stephenson
2017-01-16 10:37             ` Peter Stephenson
2017-01-16 15:04               ` Daniel Shahaf
2017-01-16 15:48                 ` Peter Stephenson
2017-01-16 15:22               ` Bart Schaefer
2017-01-16 15:59                 ` Peter Stephenson
     [not found]                   ` <CAHYJk3SB1NDj6y5TRHHsAVsyjHfZQhTzMRzTR2c-SVEc9oAwzA@mail.gmail.com>
2017-01-24 11:10                     ` Peter Stephenson
2017-01-11 21:13         ` Peter Stephenson
2017-01-17 18:36       ` Peter Stephenson [this message]
2017-01-17 22:17         ` PATCH: " Daniel Shahaf
2017-01-18  0:06           ` Bart Schaefer
2017-01-18  9:21             ` Peter Stephenson
2017-01-18  9:17           ` Peter Stephenson
2017-01-18 22:26             ` Bart Schaefer
2017-01-19  9:39               ` Peter Stephenson
2017-01-18  9:53         ` Peter Stephenson
     [not found] <CGME20170112125605eucas1p1b2539afbacec2d28d44c6fd73b0d50af@eucas1p1.samsung.com>
2017-01-12 12:56 ` Peter Stephenson
2017-01-12 15:40   ` Daniel Shahaf
2017-01-12 15:59     ` Peter Stephenson
2017-01-12 16:09       ` Daniel Shahaf
2017-01-12 16:16         ` Peter Stephenson
2017-01-12 16:23           ` Daniel Shahaf
2017-01-12 16:34             ` Peter Stephenson
2017-01-12 16:05   ` Vin Shelton

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=20170117183606.5d1db3de@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).