Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable highlighting of base functions #70

Open
yurivish opened this issue Jan 16, 2018 · 9 comments
Open

Option to disable highlighting of base functions #70

yurivish opened this issue Jan 16, 2018 · 9 comments

Comments

@yurivish
Copy link

yurivish commented Jan 16, 2018

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.

@ViktorQvarfordt
Copy link
Member

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.

@yurivish
Copy link
Author

yurivish commented Jan 16, 2018

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).

@ViktorQvarfordt
Copy link
Member

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?

@yurivish
Copy link
Author

Yes, that sounds like a good idea to me.

@ViktorQvarfordt
Copy link
Member

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

@albertas-jn
Copy link
Contributor

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.

@yurivish
Copy link
Author

yurivish commented Jan 16, 2018

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?

@albertas-jn
Copy link
Contributor

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

@ViktorQvarfordt
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants