zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: priority of execution
Date: Tue, 25 Oct 2022 19:36:25 +0100	[thread overview]
Message-ID: <dda0e27e5b29798a968f4282c9e7ec9925c5f72d.camel@ntlworld.com> (raw)
In-Reply-To: <b2f61c77-2e50-0c87-b7bf-eefa9bed0f61@eastlink.ca>

On Tue, 2022-10-25 at 10:17 -0700, Ray Andrews wrote:
> On 2022-10-25 09:08, Peter Stephenson wrote:
> > The different categories known to whence, from looking at the source,
> > are aliases, reserved words, shell functions, builtins, and binaries
> > in the file system (in the case of whence, those found via $PATH).
> 
> In that order?

Aliases are parsed while stuff is still being read in.  This is why
they're the only type that allow you to use the name of the alias as
some other type of command.

Reserved words are handled after the line has been read in, but still
quite early in parsing, because, as I explained, they need to know about
the structure of what follows.

Everying else is only examined during execution (so if a function
contains the name of one of the following types, it won't be decided
until the function's run which sort it's using --- that's not true of
aliases and reserved words, their effect gets baked into the function).

Shell functions are looked for first.  This means you can replace a
builtin or an external command with a function of the same name, and
still call e.g.

whence() { print This is a special whence; builtin whence "$@"; }
ls() { print Tthis is a special ls; command ls "$@"; }

Builtins are next, which means a builtin with the same name as an
external command is called in preference.  This is usually useful as its
faster, e.g. "test", but sometimes an annoyance, e.g. "enable" is a
shell command but may be an external printer command.  You can disable
builtins you don't need, or use a shell function workaround ("command"
always calls an external command in zsh, unlike other shells, unless
you're in compatibility mode).

External commands are last, with their own rules about the use of $PATH
or absolute paths or those relative to the current directory.

> > Autoloadable functions are a special category of function
> 
> But whence reports them specially:

Yes, just to be helpful.  You'll see once the function has been
autoloaded, it's just a normal function, and if you define a normal
function with that name the autoload flag just vanishes.  It's
really ordering rather than precedence.  If the function's already defined
it's not autoloadable, and it'll ignore attempts to make it so unless
you undefine it first.  Autoloading is just an instruction about how to
get the function if it's not there, it's not really a type of function
at all.

pws



  reply	other threads:[~2022-10-25 18:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 15:47 Ray Andrews
2022-10-25 16:08 ` Peter Stephenson
2022-10-25 17:17   ` Ray Andrews
2022-10-25 18:36     ` Peter Stephenson [this message]
2022-10-25 21:58       ` Ray Andrews

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=dda0e27e5b29798a968f4282c9e7ec9925c5f72d.camel@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@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).