SublimeText / WordHighlight

Highlight all copies of the currently selected word.
MIT License
180 stars 24 forks source link

php variables #1

Closed ghost closed 13 years ago

ghost commented 13 years ago

Currently, php variables are not highlighted. These have a form of $var12, that is an alphanumerical string starting with a dollar sign '$', and, therefore, '\\b'+regex_escape(string)+'\\b' from the current word_highlight.py does not match. I have no idea how to fix this, apart from replacing the regular expression with regex_escape(string)+'\\b', which is obviously not well suited for everybody. '(?<=[^\w$])' + regex_escape(string)+'\\b' does the job as well, but I'm not comfortable with python regex, and it would be cool if someone could verify it really works as intended.

bobthecow commented 13 years ago

I would go with '\\b(\$|@@?)?'+regex_escape(string)+'\\b' personally, as this preserves the "on word boundary"-ness of the RegEx (i also threw in the @ / @@ from ruby as a bonus match).

ghost commented 13 years ago

@bobthecow: It appears your regex should actually be like this: '\\b($|@@?)?' + regex_escape(string)+'\\b' ($ not backslashed, otherwise it doesn't work). However, it doesn't suit my particular use case: i prefer to select whole variables in my code, including '$' (with ctrl-d or double-click), so I've adjusted the word_separators setting to exclude '$' sign -- it is subjectively more convenient that way. In this scenario, the regex you provided obviously doesn't do the job. Loosening the "on the word boundary" constraint, however, makes WordHighlight to perform in a more intuitive way, at least in regards to word_separators, and by letting "expand selection" series commands to do the job of detecting what is actually a word. Letting the user to set word_separators on per-syntax basis helps too.

Anyway, I'm making a pull request to modify the plugin. I've tested the change for the best of my ability, but if the "on the word boundary" (as mr. bobthecow named it) is a core principle, feel free to reject it.