0

I am using Sublime Text 3 version 3.2.2, Build 3211.

The issue is that Sublime syntax highlighting does not work for wrongly typed PHP built-in functions. I want it to behave like Notepad++ and some other code editors where If you mistakenly type wrong PHP built-in functions then editor considers it as a normal plain text. So you are aware of typo and just in case if you don't exactly remember the function name. You can rectify mistake as soon as you see that code color didn't change to what they are set for reserved keywords.

I am taking an example of PHP built-in string function strlen().

In Notepad++

Here I deliberately typed strlen to strle to show you what I meant. Function name color turns to black:

enter image description here

When I type correct function name, the function name color becomes blue:

enter image description here

In Sublime Text 3

Wrong function name is still blue. You can't say it is typed right or wrong:

enter image description here

You can see that wrong PHP function does not change the color. So I can't figure out when I unintentionally type wrong function in large code. How can we fix this issue?

1 Answer 1

1

This behavior is color scheme-dependent. I use the Neon Color Scheme (nb: I am its author), and your code looks like this:

screenshot

As you can see in the upper snippet with strle, the function name is in green, which all generic (i.e., non built-in) functions are. The relevant scope is meta.function-call.php variable.function.php, which indicates as much.

In the lower snippet where strlen is spelled correctly, the syntax highlighting is completely different. The relevant scope there is meta.function-call.php support.function.string.php, indicating that the function is not only built-in, but it is a string function as well. If you wanted to, you could adjust your color scheme to highlight all string functions differently than other builtins.

I don't know what color scheme you are using, but it apparently doesn't differentiate between different types of functions. Unfortunately, unless you are gifted in both reading JSON and interpreting Sublime scopes in your head, there really isn't a way to see if a given color scheme supports this differentiation or not. I designed Neon with the goal of making as many language constructs as possible look as good as possible, but not all (in fact, not many) color scheme authors share this goal, so if you don't prefer Neon you'll have to look around some. There are currently in the neighborhood of 300 different color schemes on Package Control. If you'd rather alter your current color scheme and the docs don't answer all your questions, just post a new question and I'd be glad to help.

Sign up to request clarification or add additional context in comments.

15 Comments

Thanks for your detailed answer. I'm using Dreamweaver color scheme. Here's the link: github.com/mghweb/SublimeDreamweaver. Since I have been using DW for a long time since I started coding so no other color scheme looks nice and comfort to my eyes. I tweaked this color scheme as it had some flaws regarding HTML form tags etc. So the scope you talked about needs to be changed in my current color scheme? You were right that it is color scheme dependent because when I switched to Sixteen color scheme the color of misspelled PHP function changed.
One another question associated with color scheme is that can we make Sublime to highlight all occurrences of matching text. Currently it can only put border around the text?
@Sachin Ah yes, Dreamweaver. I used that back in the 90s at my first (paid) coding job... Anyways, yes, if you add separate scopes for meta.function-call variable.function and meta.function-call support.function.string (or just meta.function-call support.function) to your color scheme, you'll be fine. For your 2nd comment, can you write that up as a new question and include details about what exactly you're doing? Thanks.
Glad to know you tasted it too! These scopes solved my one problem but created some another. The new problem is that the function name doesn't change its color at the place where I am calling it. Now I am thinking to leave this tweak procedure as it is wasting my time and energy. Anyway, thanks for your help. And for my second comment question, I searched and found that in ST3 it is not yet possible.
@Sachin Check out ST4. You didn't say exactly what you were doing to create the outlines, but I know it has a number of new features for highlighting, as well as a ton of other stuff. I've been using it for over a year, since the first alpha builds were in private testing, and I love it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.