From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11692 invoked by alias); 18 Sep 2015 21:53:08 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20591 Received: (qmail 23375 invoked from network); 18 Sep 2015 21:53:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=+MKkM67TabV3umq8DhHRtwbHKZFadeJWgt3IxwV5IF0=; b=XCx2nE17kvs/OgOPUsbdGBM8SuDHvn6CLcpwZ6PrNE9AFFBtqhGZdoIg1jgUTRjxmi 1NRePNsjN59ERV8j/ei6/3gXqB3HZkEXXkBSxIbmExAesNv3RQmpIBep5CS/nplMJiLA EIOEp7nRxCBXvJpJCeHKCpPHBa6hf/EHP3AmNbg4vOv6WtShiFE4iCnpj42svxEqwdY1 lXm7G4wslCgDxkQcEIwXzKpIlmLtEoSl/oqT8aYrXAOquLx5zfHCztsnl11dkNpn8o4Z WxyDxcNFfmFnHWD19FtdJbN8Lv5vqCARD3AVWTcWgiO2r0U3hRsNOVgxdacu96rc6wLz XFPg== X-Gm-Message-State: ALoCoQln8TVMjK3QrEW2OQs/i86jaAaJThzrCMaXhTJ+hHPeyhj4L2kNS4EqANUV2FPPX3wa3I1f X-Received: by 10.202.76.66 with SMTP id z63mr4956928oia.19.1442613183626; Fri, 18 Sep 2015 14:53:03 -0700 (PDT) From: Bart Schaefer Message-Id: <150918145300.ZM27125@torch.brasslantern.com> Date: Fri, 18 Sep 2015 14:53:00 -0700 In-Reply-To: <55FC5BC8.4040107@eastlink.ca> Comments: In reply to Ray Andrews "Re: Autoload vs regular function" (Sep 18, 11:45am) References: <150918101506.ZM26893@torch.brasslantern.com> <55FC5BC8.4040107@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Autoload vs regular function MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 18, 11:45am, Ray Andrews wrote: } } Can you rough in an example of that for us Bart? Sounds like an elegant } idea. Functions/Misc/tetris in the zsh distribution is a perfect example of this already. It defines a whole bunch of helper functions (most of which end up becoming zle widgets) and a single entry point function "tetris" which kicks the whole thing off. Note at the very end of Functions/Misc/tetris, the function that it defined is explicitly called. This is so tetris can be autoloaded in the default zsh style. If you do "autoload -k tetris" the command is run twice. (Many autoloadable functions in the zsh distribution test for KSH_AUTOLOAD before calling themselves this way; tetris probably ought to as well, but currently doesn't.) } I wonder if it is possible that when one types a command that is not } found, it could trigger a sort of search in some directory for a } script that would itself source the very command not found and then } run it? Sorta a reinvention of autoload but maybe more transparent. Recent zsh support a command_not_found_handler function which is run if a the searches of $fpath and $path do not find anything. So you can do this by building a custom search in command_not_found_handler. I don't know that this any more "transparent" than otherwise. Also the command_not_found handler runs after the parent shell has forked, so anything it loads does not appear in the parent. E.g. to always attempt to load functions from a .zwc file in the current working directory, you could: command_not_found_handler () { FPATH=$PWD autoload +X $1 "$@" } Similarly if you don't like zsh's way of handling autoloads, you can do you own like this: auto_load_me () { FPATH=/my/custom/fpath autoload -X } This is [almost!] the same as writing autoload auto_load_me except that the custom fpath is asserted. I say "almost" because things like sticky emulation get handled a little differently when using the "autoload -X" command, but that is pretty esoteric. Of course you can throw in other things besides just fpath changes, you have a whole function body to play with, but at some point you're just ruining the whole purpose of autoload and might as well define the real function. -- Barton E. Schaefer