-
Notifications
You must be signed in to change notification settings - Fork 1.3k
No highlighting for aliases containing function #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's because when highlighting For this case in particular, I'd move the function definition out of the alias. |
Not sure if I understand correctly, but are you saying that you are analyzing the value of the alias somehow? Wouldn't be better to highlight any alias regardless its value? |
Yes, we do, in order to highlight |
I strongly recommend to change the alias's definition (or convert it to a function) as it'd DTWT in a SHORT_LOOPS context. |
@jtyr |
I think it would be really useful to have a switch to enable/disable the validation of alias values. I would personally prefer to have any defined alias green even if the value would lead to non-existing command. Something like this: ZSH_HIGHLIGHT_STYLES[validate_alias_value]='no' |
That's not really an option as the words after an alias may not be arguments.
or
In both cases
ZSH_HIGHLIGHT_STYLES ).
I second the strong recommendation to at least move the function definition out of the alias. It seems odd to redefine a function each time an alias is run aside from the other issues @danielshahaf pointed out. Regarding highlighting function use after definition in one line, we could handle the usual case of not being in a loop or behind a conditional (including |
It would be really great if this behavior would be configurable in any way. I think it's more important to highlight perfectly valid alias as green than invalid alias as red. |
@jtyr Please distinguish the desired behaviour from the proposed way to obtain it. Both @phy1729's and my ideas about changing the highlighting of function definitions would cause the alias not to be highlighted in red, without adding configuration knobs (which, if necessary, may depend on #362). In any case, since consensus is that your alias should be changed, I'm not sure I'd accept that particular alias as a use-case/justification for any functional change. Hard cases make bad law. Note: two distinct, but related, topics are being discussed: 1. Highlighting aliases as green iff they exist (as older zsh-syntax-highlighting did); 2. Highlighting function define-and-call. |
I understand that if I externalize the function it would work just fine. But there is a reason why I have the function definition inside the alias and from shell point of view that's absolutely valid alias definition. I believe it would make sense to have an option to highlight every defined alias as green regardless the validity of its value. |
Yes, it's syntactically valid. That hasn't been questioned. As to the reason, I don't see what it is.
You have already said so and been replied to. |
so in the roadmap, zsh-syntax-highlighting will not deliver this feature at all, i.e. support alias correct-highlight include function definition? |
> That's because when highlighting `f(){ ls -la; }; f` the second f is not recognised as a function (as it isn't defined yet). More or less a dup of #223.
>
> For this case in particular, I'd move the function definition out of the alias.
so in the roadmap, zsh-syntax-highlighting will not deliver this
feature at all, i.e. support alias correct-highlight include function
definition?
The whole reason this ticket remains open is in order to track changing the behaviour of this case.
However, see above (#803 (comment)): the use-case given is the moral equivalent of `#define f() foo(); bar();` in C: it's syntactically valid but liable to DTWT in certain contexts. As such, it's not high priority for us.
This may be an instance of "hard cases make bad law". If anyone has a use-case for `f(){}; f` that /doesn't/ have the aforementioned drawbacks, it would be useful to know that.
|
If I define an alias:
and then type
xxx
, it highlights it just fine. But if I define alias containing a function:and then type
xxx
, it doesn't highlight it as a known command.The text was updated successfully, but these errors were encountered: