From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16068 invoked by alias); 29 Jan 2017 17:58:22 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40458 Received: (qmail 1254 invoked from network); 29 Jan 2017 17:58:22 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-7.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.71):SA:0(-1.2/5.0):. Processed in 1.246715 secs); 29 Jan 2017 17:58:22 -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.2 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.71 as permitted sender) X-Originating-IP: [86.21.219.59] X-Spam: 0 X-Authority: v=2.1 cv=SYcKDalu c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=MWUjAzoEKyAA:10 a=q2GGsy2AAAAA:8 a=JWrHJn-yHlTKt6UCHiYA:9 a=CjuIK1q_8ugA:10 a=z9dJwno5l634igLiVhy-:22 Date: Sun, 29 Jan 2017 17:58:15 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: PATH: autoload with explicit path Message-ID: <20170129175815.15366274@ntlworld.com> In-Reply-To: References: <1485529979.987251.861563792.06CCDCAC@webmail.messagingengine.com> <20170127162440.10a5c85b@pwslap01u.europe.root.pri> <1485542415.1037033.861766968.196E6FB9@webmail.messagingengine.com> <20170127184448.5591e976@pwslap01u.europe.root.pri> <20170128191248.4718b24c@ntlworld.com> <1485692865.2441595.863153472.2F8272F0@webmail.messagingengine.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 29 Jan 2017 08:11:04 -0800 (PST) Bart Schaefer wrote: > Consider for example that several of the autoloadable functions in the > zsh distribution rely on "autoload colors". > > If autoload behaved the way you suggest, this would break, because the > colors function would not be found at the absolute path from which the > calling function was loaded -- unless the writer of the calling function > has used "autoload -d", of course. But if we're now relying on the > author to use the correct options for autoload, we're right back where > we started -- might as well rely on the author to make his function > suite "relocatable" by way of $function_source as well, and that is > now possible. > > There's no magic solution that automatically covers all the variations > without cooperation from both the writer and the installer of the suite. That's roughly my thinking --- any attempt to magic it gets very messy very quickly --- and you don't need to. Here's how it can work. I think it puts the onus to do the clever stuff on the function code writer, which is the right place. 1. User gets a heap of functions and is instructed to put them all in the same directory (or under the same directory, we have the flexiblity to make it work with a set of subdirectories). That's not controversial anyway, I don't think. 2. User puts: autoload -Uz /wherever/they/put/it/mainfunc in their start up. Note it'll still work if they rely on $fpath --- mainfunc is resolved when loaded, so the code below still works. So you are protected against the user doing anything as long as it's some valid autoload that works in the version of the shell in us. No special instructions are needed. 3. mainfunc contains: zmodload zsh/parameter if (( ${+functions_source} )); then # If that's available, load by absolute path is available. # The -R barfs immediately if the function can't be found # (optional extra to simplify error handling). # You can add -d if you want to search $fpath, too. autoload -RUz ${functions_source[mainfunc]:h}/{other1,other2,other3} # ... or whatever. else # We're stuck with old-fashioned fpath. Add warning, check, whatever. autoload other1 other2 other3 fi This can be tailored to suit. Any half-baked magic in the shell C implementation can't. To repeat, I'm not in any case interested in doing half-baked magic in the shell C implementation. so let's not go down that route again. pws