From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28475 invoked by alias); 8 Jan 2017 20:14:57 -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: 40309 Received: (qmail 18827 invoked from network); 8 Jan 2017 20:14:57 -0000 X-Qmail-Scanner-Diagnostics: from mail-vk0-f49.google.com 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(209.85.213.49):SA:0(-0.0/5.0):. Processed in 2.040236 secs); 08 Jan 2017 20:14:57 -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=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.213.49 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=kwrykCPN/Gqennv6N8tvsg8otdPSvErOf9rv1uoYerE=; b=WlsQGV606OYKP1Z5V5eB30x6WSZGI14xWNDMjR/XbHyDIwH9GsiRqH/Goos/4VrW6T 9yrjt0OAOh9++6ViWRapzuWRO0/EWIjDrs8JlmAeMC/q+ORN3blfS9Hjtqqqa+eHs+vI ZRGhRppsMIVGAAVstoT01r9Ehyje5h0t4UjXOLTjUj1Gyse3HfdEmEf4yvqm9ec0L1IQ SWzsyE9fjMbYnbs9pcbBRFcSDr8lXtmkBOjnxLfrkfNla6kHWFCUeVONiDGpq7IPWFCW 000qUcbZRy4zjvarBtLQoxE2avmD7mw33nbWlyUg5dbNrl2O5QXNOvAwhDDIe6Xe8l/M t7Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=kwrykCPN/Gqennv6N8tvsg8otdPSvErOf9rv1uoYerE=; b=g7cClhbH0Q0aYWL8G0Bealx45OW4NGNQcfYQW4MP03mNgX4ejWGyRgv1RlvIALtPrH 7rUo6F/uXhtF7zmAC6dzCmvIy/V/R60VPy4bDhhJ/akAIZZdPQXeUWkrbl3mxJ5AXMZx SZ5vh8tatfdq3SsOJimg4INqKTObmHxuHLCJSJKyuuBebYNwTWRSADYtRkb3ZIWH7D3Q d1s35lQvtJtDJ12HEcrH1HNECHzLcJSnh2Wp/vQx+WD6mXpQQC16Eyg9A9JgsrQgRnw3 VQcgOtvuuHsj/+UtIuQqTWI8kzOj+12iFX0M8zJpeS5Zqm/H/brWVzRMfTUFq5Jrom0V NMfQ== X-Gm-Message-State: AIkVDXJvlFB9qjAfRCH3hiMTYpvVGV1dvPM1vo1KPk+61iXe+hFi74KUSqN05TGtBpquZA== X-Received: by 10.31.87.6 with SMTP id l6mr25013910vkb.116.1483906488826; Sun, 08 Jan 2017 12:14:48 -0800 (PST) From: Bart Schaefer Message-Id: <170108121454.ZM10678@torch.brasslantern.com> Date: Sun, 8 Jan 2017 12:14:54 -0800 In-Reply-To: <20170108191922.3d3de59f@ntlworld.com> Comments: In reply to Peter Stephenson "Re: Defining function based on alias" (Jan 8, 7:19pm) References: <20170107221659.1b9232da@ntlworld.com> <20170108191922.3d3de59f@ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: Defining function based on alias MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 8, 7:19pm, Peter Stephenson wrote: } Subject: Re: Defining function based on alias } } I am about to commit the following, which I hope will hope will stop } people coming to grief with this common confusion. Please say if you } see any problems. No problems, but -- if it's possible to detect this situation, why not simply suppress the alias expansion and define the function as named, rather than trigger an error? Etc/FAQ should be updated too. I never remember how to rebuild FAQ from FAQ.yo ... can someone check my yodl syntax? diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index 6b635ea..9eb23db 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -574,7 +574,8 @@ tt(EXTENDED_GLOB). it() Aliases and functions: itemize( it() The order in which aliases and functions are defined is significant: - function definitions with () expand aliases -- see question \ + in zsh versions 5.3.1 and earlier, function definitions with () + expand aliases -- see question \ link(2.3)(23). it() Aliases and functions cannot be exported. it() There are no tracked aliases: command hashing replaces these. @@ -704,6 +705,12 @@ label(23) the manual). Note also that the mytt(;) at the end of the function is optional in zsh, but not in ksh or sh (for sh's where it exists). + Recent versions of zsh support anonymous functions with argument lists, + so you can create an alias that acts like a function. + verb( + alias cd='() { builtin cd "$@"; print -D $PWD; }' + ) + Here is Bart Schaefer's guide to converting csh aliases for zsh. enumerate( @@ -711,6 +718,9 @@ label(23) then in zsh you need a function (referencing tt($1), tt($*) etc.). Otherwise, you can use a zsh alias. + In zsh version 5.0 and later you can use an anonymous zsh function in + combination with a zsh alias. + myeit() If you use a zsh function, you need to refer _at_least_ to tt($*) in the body (inside the tt({ })). Parameters don't magically appear inside the tt({ }) the way they get appended to an alias. @@ -772,13 +782,17 @@ label(23) alias l='/bin/ls -F' l() { /bin/ls -la "$@" | more } ) - mytt(l) in the function definition is in command position and is expanded + mytt(l) in the function definition is in command position and may expand as an alias, defining mytt(/bin/ls) and mytt(-F) as functions which call mytt(/bin/ls), which gets a bit recursive. This can be avoided if you use - mytt(function) to define a function, which doesn't expand aliases. It is - possible to argue for extra warnings somewhere in this mess. + mytt(function) to define a function, which doesn't expand aliases. + + For zsh versions after 5.3.1, alias expansion of function names is an + error by default and the option tt(ALIAS_FUNC_DEF) must be active to + expand aliases in function names. However, this option em(is) active + in compatibility modes where aliases are supported. - One workaround for this is to use the "function" keyword instead: + Here is an example using the "function" keyword instead: verb( alias l='/bin/ls -F' function l { /bin/ls -la "$@" | more }