Julia-sublime icon indicating copy to clipboard operation
Julia-sublime copied to clipboard

Option to disable highlighting of base functions

Open yurivish opened this issue 8 years ago • 9 comments

Hello! I've been enjoying this package for some time and have a question — is it at all possible to disable the syntactic highlighting of Julia Base functions?

I often have e.g. a local variable inside a function named start, which maddeningly gets colored and italicised just because it happens to use a word also used as a function name in Base.

I see there is a list of functions in Julia.sublime-syntax: base_module_func: (?<!\.)(?:BLAS\.(?:asum|axpby!|axpy!|blascopy!|... but I'm not sure how best to deal with either disabling it for myself or adding an option to disable highlighting to the package, or whether there's a better option available.

yurivish avatar Jan 16 '18 09:01 yurivish

Hi, thanks for opening an issue!

This is a good question, and I don't know how to best deal with it. Most other language syntax highlighters will have the exact same problem. You could maybe have a look at some other languages and see how they deal with this.

On the other hand, is it a good idea to shadow globally-predefined variables? A common annoyance in python is that list is <class 'list'>, so it is not a good idea to redefine list = [1,2,3]. In this case it is nice if the syntax highlighter shows such keywords.

I think this should be discussed further. Ideally getting more input from other users.

ViktorQvarfordt avatar Jan 16 '18 10:01 ViktorQvarfordt

I've discovered that what controls the highlighting is lines 493-494:

    - match: '{{base_funcs}}'
       scope: variable.function.julia support.function.julia

Commenting these out suffices to disable the highlighting for variable names.

On the other hand, is it a good idea to shadow globally-predefined variables?

It seems to me that unlike other languages Julia's design makes the use of highly generic names in the global namespace inevitable. Fortunately, Julia's scoping rules make their use as variable names possible, and you can find examples of uses of such variable names in base Julia itself.

Not to mention that this highlights a fixed set of identifiers, rather than doing any sort of semantic analysis, so it's going to hit exactly the names in Base only, rather than the actual set of global identifiers (and perhaps you're using a baremodule, where Base names aren't even imported, in which case it would highlight names that don't conflict but not highlight ones that do).

yurivish avatar Jan 16 '18 13:01 yurivish

Good point, and one can always access the variable as Base.variable if it has been shadowed.

I do not see how we can make this into an option. Do you think we should simply remove those two lines?

ViktorQvarfordt avatar Jan 16 '18 13:01 ViktorQvarfordt

Yes, that sounds like a good idea to me.

yurivish avatar Jan 16 '18 13:01 yurivish

Ok. However, I won't make a commit immediately: I'll keep this open some days to give the others a chance to comment.

ViktorQvarfordt avatar Jan 16 '18 13:01 ViktorQvarfordt

As far as I understand, the lines that you quote are not directly responsible for highlighting, but just define the syntax. The actual highlighting is done by the color scheme. A better solution is to create/edit a color scheme that does not highlight variable.function.julia and support.function.julia scopes. If you remove them from syntax definition, it will not be possible to highlight them for those who choose so.

albertas-jn avatar Jan 16 '18 20:01 albertas-jn

Hi @albertas-jn , thank you — that does sound like a potentially better approach. I'm still new to Sublime internals, however, and don't quite understand which color scheme you are referring to here.

It seems the file you mean would be a Julia-specific color scheme referencing Julia-specific scopes, which I don't see inside the Julia package internals. Where do you suggest I look?

yurivish avatar Jan 16 '18 22:01 yurivish

Color schemes are different from specific language support packages, like Julia-sublime. Color schemes are usually written to be used with different languages.To choose a color scheme go to Preferences -> Color Scheme.

To modify your current color scheme, first locate it in the Installed Packages directory. It is probably a zipped archive. Extract a .tmTheme file, rename it, and put it in Packages/User directory. Choose your new color scheme via Preferences ->Color Scheme. Now you can edit the file, and you will see the changes immediately. Find the scopes variable.function and support.function and assign text style you want. Usually the styles are defined for scopes that are as general as possible, i.e. they do not have .julia at the end, unless you want the setting to apply to Julia files only, but not other languages.

More info here: https://www.sublimetext.com/docs/3/color_schemes.html https://docs.sublimetext.info/en/latest/reference/color_schemes.html

albertas-jn avatar Jan 17 '18 08:01 albertas-jn

That is a good point. Still, one could argue that this package should not the scope support.function to functions from base, because the convention in Julia is to often shadow these built-ins, making it impossible to tell if a variable is support.function or not. For the case of Base.function we of course know that the symbol is support.function.

I have no strong opinion in this question.

ViktorQvarfordt avatar Jan 17 '18 15:01 ViktorQvarfordt