From: Bart Schaefer <schaefer@brasslantern.com>
To: Aryn Starr <whereislelouch@icloud.com>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Macros created via global aliases don't work
Date: Mon, 12 Aug 2019 17:31:13 -0700 [thread overview]
Message-ID: <CAH+w=7afXtHULHf4WZzqyvV0Jqnc_hnw9hi1pdrentzfsDt1=A@mail.gmail.com> (raw)
In-Reply-To: <5E74A664-7781-4FDC-B640-FDFDCDB2A104@icloud.com>
On Mon, Aug 12, 2019 at 1:55 AM Aryn Starr <whereislelouch@icloud.com> wrote:
>
> alias -g MAGIC=')"'
> alias mdoc='eval "$(m_doc "$*" "$0" '
>
> mdoc Usage: Some documentation here. MAGIC
You've created an ambiguous "sentence". Aliases are not really
macros; they are both expanded and parsed left-to-right, not fully
expanded before parsing begins. The ambiguity is that because you've
hidden the closing paren from the parser, it follows through the
depth-first interpretation rather than the breadth-first.
First mdoc expands, and then that expansion is parsed, so now the
parser is now working inside the command substitution, and when MAGIC
expands the shell sees it as part of the m_doc command rather than as
part of the mdoc command, if you see what I mean.
I think you can unambiguously get what you're after by using
alias mdoc='m_doc '
alias -g MAGIC='| { eval "$(read -d "" -r -E)" }'
prev parent reply other threads:[~2019-08-13 0:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-12 8:54 Aryn Starr
2019-08-13 0:31 ` Bart Schaefer [this message]
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='CAH+w=7afXtHULHf4WZzqyvV0Jqnc_hnw9hi1pdrentzfsDt1=A@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=whereislelouch@icloud.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).