Skip to content

regexp highlighter depends on the RE_MATCH_PCRE option #748

Open
@danielshahaf

Description

As pointed out in #747 (comment) (by @jnooree), the regexp highlighter runs under whichever setting of the RE_MATCH_PCRE option was in effect when _zsh_highlighter was invoked.

This gives rise to two converse issues:

  1. If somebody, for whatever reason, calls _zsh_highlight with the RE_MATCH_PCRE option temporarily set to the opposite of whatever it is normally set to when z-sy-h is invoked (e.g., some_other_plugin() { setopt localoptions norematchpcre; _zsh_highlight } in a setup where that option is set when z-sy-h is invoked the usual way), the regexp highlighter will parse its patterns according to the new value of the option. This may cause patterns to fail to compile (if they use PCRE features that aren't supported by the local regcomp(3), or vice versa) or to match incorrectly. In any case, depending on the option's current setting doesn't sound right: whether a pattern is an ERE pattern or a PCRE pattern doesn't depend on the option settings at the time of any particular function call.

  2. Running the driver under canonicalized option settings (Canonicalize option settings earlier #536) would constitute a breaking change for users who deliberately set that option and use PCRE patterns in ZSH_HIGHLIGHT_REGEXP.

One straightforward way to fix both issues is to extend the regexp highlighter's API with a way to specify whether matching should use the -regex-match operator or the -pcre-match operator. Should such a setting be per pattern? That would provide modularity: the highlighter could be used by different modules and those modules won't all need to agree on whether to use PCRE or ERE.

An alternative way to fix (2) only would be to query ${zsyh_user_options[rematchpcre]}.

@disarmer @jnooree WDYT?

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions