Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Disabling null elision (was: Re: Most Recent File)



On Mon, Oct 25, 2021 at 10:42 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>
> Roman Perepelitsa wrote on Mon, 25 Oct 2021 20:02 +00:00:
>
> > It's also nice that this option would affect parsing, only evaluation,
> > so it won't be necessary to care about it when defining functions.
>
> How so?

Some options can be set within a function for the function to work as
the author has intended. For example, extended_glob.

    function foo() {
      emulate -L zsh -o extended_glob
      # can extended-glob here to one's heart's content
      [[ $1 == a## ]]
    }

Other options must be set when the function is defined. For example,
brace_expand.

    # if brace_expand is unset here, bar is screwed
    unset brace_expand  # bwa-ha-ha

    function bar() {
      emulate -L zsh -o brace_expand  # this won't help
      typeset var{1,2,3}=42
    }

    setopt brace_expand  # this won't help either
    bar  # oh no!

Options of the second kind cause more grief.

As Bar says, autoload -Uz is key when it comes to loading plugins and
sourcing is a losing game (I learned this from Bart earlier).
Sometimes you still have to have a function in a plugin that must run
with user options but at least that's just for evaluation and not for
parsing.

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author