Skip to content

$_ incorrectly highlighted red #619

@mxmilkiib

Description

@mxmilkiib

$_ (dollar underscore) is the last parameter from the previous line. I often (with autocd on) enter "$_" directly after a command to jump into the destination directory. However it's always highlighted red. Apologies if this is covered by another issue, I went through a number but couldn't find anything directly related. Thanks.

Activity

danielshahaf

danielshahaf commented on Jun 24, 2019

@danielshahaf
Member

Are literal directory names highlighted in green at command position when AUTO_CD is set? AFAICS they aren't [can't test this myself right now], so you're essentially asking for AUTO_CD support to be added. (Once literal directory names are handled, simple parameter expansions will DTRT too.)

Would you be interested in contributing this feature?

danielshahaf

danielshahaf commented on Jun 24, 2019

@danielshahaf
Member

By the way, M-. (Alt+.) is equivalent and has fewer keystrokes.

mxmilkiib

mxmilkiib commented on Jun 24, 2019

@mxmilkiib
Author

Whoops, AUTO_CD paths are made purple (on my system) not green.

I'm afraid I don't have the understanding, time or energy to implement this.

Alt-. doesn't work for me, I guess either conflict with another zsh script or bad key binds. Thank you for the tip though.

phy1729

phy1729 commented on Jun 24, 2019

@phy1729
Member

It's a bit more complicated than just supporting AUTO_CD. Currently _ is not recognized as a parameter name

readonly parameter_name_pattern='([A-Za-z_][A-Za-z0-9_]*|[0-9]+)'
. The hard part is expanding _ properly. We'd need to save the value of _ and then special case the expansion code because _ will have changed many times over once we've gotten to here

danielshahaf

danielshahaf commented on Jun 25, 2019

@danielshahaf
Member

That pattern would match $_ 's name, but if we are able unable to compute the correct expansion, we might have another use-case for the envisioned indeterminate style — not just for $_ but for any [[ ${(t)foo} == *special* ]] parameter at command position, unless whitelisted as an exception?

danielshahaf

danielshahaf commented on Jun 25, 2019

@danielshahaf
Member

See #617 for indeterminate (although that term isn't used there).

danielshahaf

danielshahaf commented on Jun 25, 2019

@danielshahaf
Member

My reading is two separate issues:

  • Support AUTO_CD.
    Don't expand special parameters at command position.
phy1729

phy1729 commented on Jun 25, 2019

@phy1729
Member

Indeed it does match $_ oops. I agree in general special parameters should use a indererminate style; however, I think $_ is useful enough to special case. There may be a cleaner way, but worst case we could save ${${(z)BUFFER}[-1]} on zle-line-finish.

danielshahaf

danielshahaf commented on Jun 25, 2019

@danielshahaf
Member
phy1729

phy1729 commented on Jun 25, 2019

@phy1729
Member

Nothing. However, highlighting on the modified line would already be incorrect for those users (and we do document that we should be sourced last).

danielshahaf

danielshahaf commented on Jun 26, 2019

@danielshahaf
Member

Fair enough. Re 'cleaner way', I thought we could have zle expose the REPL-level value of $_ through a new preset variable (akin to BUFFER, WIDGET, &c). WDYT?

danielshahaf

danielshahaf commented on Jan 16, 2020

@danielshahaf
Member

For the record, AUTO_CD support is in #669 (PR for 0.8.0) and parameters in command position are #674 (has WIP PR). Support for $_ specifically would require further work, as discussed in this issue.

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mxmilkiib@phy1729@danielshahaf

        Issue actions

          $_ incorrectly highlighted red · Issue #619 · zsh-users/zsh-syntax-highlighting