-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Highlight command and process substitution #512
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
Highlight command and process substitution #512
Conversation
Tests only fail for 5.0.8.
and
Not sure why yet. |
Seems *: Nearly never because it's possible that a user could nest an unclosed |
Seems `${(z)` in 5.0.8 splits `: foo$(echo bar` into `:` and `foo$(echo bar ` (note the extra space at the end). Since this is a zsh bug that's already been fixed and will nearly never* effect the highlighting the user sees (since the off by one will almost always be past the end of the buffer), can we just add a condition in the tests to expect the wrong output on zsh 5.0.8?
Sure. Making the condition dependent not on $ZSH_VERSION but on [[ ${${(z):-': foo$(echo bar'}[2]} == *' ' ]] (sp?) would be nice, if it's not much effort.
*: Nearly never because it's possible that a user could nest an unclosed `$(` command substitution inside of a backtick command substitution.
So... If someone nests a $() inside backticks under 5.0.8, their highlighting will be off-by-one until they type the closing paren? I think we can live with that :-)
Cheers,
|
cf8d151
to
76f6ac6
Compare
It wouldn't be hard, but I think it would be better to check $ZSH_VERSION to catch possible regressions in the future (hopefully before they become part of a release). The latest commit reflects this although the condition would be easy to change if you still think the other test is better. |
To catch regressions in ${(z)} is zsh's test suite's business, not ours. I vote for the functional test here and a regression test in zsh's test suite. Makes sense? |
76f6ac6
to
74056f5
Compare
Works for me. Rebased. |
Ty. Still planning to review/test once I'm at my workstation. Haven't had time to breathe. |
Reviewed. Haven't tested (not at workstation). Kudos for the work & thanks for patience. Does zsh have a regression test for that 5.0.8 bug? |
XXX -> parse_list? Using the zsh grammar meaning of "list". |
74056f5
to
7af5ca9
Compare
Not quite correct since the function can highlight multiple lists. I don't think zsh has a name for one or more lists. |
What do you mean by "multiple lists"? A list can contain other lists, e.g., a list that contains an
|
"20 39 default" # "is `echo equal` to" | ||
"20 39 double-quoted-argument" # "is `echo equal` to" | ||
"24 35 back-quoted-argument" # `echo equal` | ||
"25 28 builtin" # echo | ||
"30 34 default" # equal | ||
"41 55 default" # `echo 6 times 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the backticks themselves be highlighted? Quotes and command/process substitutions are all highlighted. I suppose we could highlight backticks as magenta, like $(…)
, since both of these are subject to word splitting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That wouldn't be consistent with single, double, and dollar quotes, but then again those are quotes and these are command substitutions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What wouldn't be consistent? The colour (yellow v. magenta), or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the quoting styles, the quotes themselves are not given a special style. If $(
and )
and backticks are, that would be inconsistent between the two; but they are different syntactical constructs. Additionally I think magenta (or any other really) highlighting all the words not otherwise highlighted in a command substitution is a bit much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that highlighting all words inside a cmdsubst as magenta is a bit much. How about highlighting $(
, )
, `
as command-substitution-delimiter
, defaulting to magenta, and keeping plain words inside the cmdsubst unhighlighted? We could even keep the command-substitution
group matching the entire $(…)
construct so people could assign to it in themes.
An orthogonal question: if we had command-substitution-{delimiter-,}$(( N++ ))
styles, with $N being the nesting depth, we could have a rainbow parentheses theme. Featuritis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we'd consider that when coming up with zstyles for #362 . I like the delimiter idea. How about the latest two commits?
Note: : "$(: foo)"
will still have foo highlighted yellow since there's the double-quoted-argument highlighting applying to the whole of the double quotes. Not sure what if anything to do about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delimiters LGTM.
Re foo
in : "$(: foo)"
, I don't think it should be yellow since the lexing rules of double-quoted strings (e.g., backslash escape sequences) don't apply there. That's not to say whether or not it blocks merging or releasing; just to say that I don't think it's useful for that foo
to be yellow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I don't know what to do about it. In theory
: ${ZSH_HIGHLIGHT_STYLES[default]:=fg=default}
would help, but it appears to make no difference here. Additionally the yellow would still show through for path
styled strings.
Reviewed. Great work! Thanks for splitting the noop changes to their own commits. |
After |
Similar for |
I don't see the similarity: here, To be clear, in my example, I'd typed |
Oh, the magenta is because the whole |
Ah, fair enough. At the risk of shedding bikes, should the whole of |
That's #202. |
67b33f6
to
38d7573
Compare
in_array_assignment=true | ||
else | ||
# assignment to a scalar parameter. | ||
# (For array assignments, the command doesn't start until the ")" token.) | ||
next_word+=':start:' | ||
if (( i <= end_pos )); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is incorrect. Should be
(( start_pos + i <= end_pos ))
Fixed up in latest branch.
38d7573
to
3e9c7b9
Compare
I agree, but I don't know what to do about it. In theory
`: ${ZSH_HIGHLIGHT_STYLES[default]:=fg=default}`
would help, but it appears to make no difference here. Additionally the
yellow would still show through for `path` styled strings.
Two things come to mind:
1. zle has some issues with composing multiple styles for the same offsets, e.g., I think `region_highlight=("1 2 fg=foo" "1 2 bg=bar")` doesn't results in fg=foo,bg=bar but in bg=bar. (I'm not sure about this specific example but that's the gist.) Depending on how you tested you may have run into that. That'll have to be fixed in zle.
2. We could break down the double-quoted string and only set fg=yellow for the parts outside of any inner command substitutions, e.g., in «: "foo `bar` baz"» we'd add separate ranges for the «foo » and « baz». I think that's what pws would describe as a finite amount of effort ;-).
|
phy1729 commented on this pull request.
This condition is incorrect. Should be
```(( start_pos + i <= end_pos ))```
Fixed up in latest branch.
Regression test?
|
No functional change.
No functional change.
This will allow for highlighting $( ) and similar.
This allows for callees to prepend highlights before $reply after the length of the feature (e.g. command substution) is known.
This will allow for correct path_prefix highlighting in backticks.
Prepares for next commit. No functional change.
No functional change.
No functional change.
This allows a caller to know if the command or process substitution is complete.
3e9c7b9
to
f5f3bd9
Compare
f5f3bd9
to
565463c
Compare
Closes #139 and #494.
Needs naming suggestions for things with
XXX
, but should be otherwise ready,