3 ms·
Yes, nice idea. For example, it might be helpful to have different colors for local variables, global variables and fields. If you accidentally shadow a variabl
by qznc 10y ago
Yes, nice idea. For example, it might be helpful to have different colors for local variables, global variables and fields. If you accidentally shadow a variable, you might notice this way.
Likewise, highlight macros in C and make them different to variables/functions.
- cygned 10y agoSomething like this? https://github.com/jaxbot/semantic-highlight.vim https://github.com/jaxbot/semantic-highlight.vim
- Adverblessly 10y agoEDIT: Actually, I think I misunderstood what you meant. What you are describing sounds like regular syntax highlighting to me. This is my current theme: http://imgur.com/a/cQbWL http://imgur.com/a/cQbWL You can see the level of customization available fits with what you described. And it has really helped many times in the past, preventing all sorts of silly mistakes that could have been hell to debug. Like shadowing a variable :)
- marmaduke 10y agoIntelliJ & MATLAB both change highlighting to indicate variable scoping etc, so it's neither unseen nor impossible, just uncommon in simpler editors.
- amk_ 10y agoMore advanced tokenizers are able to emit different tokens for those scopes, but not all syntax highlighters differentiate between them. The online Textmate theme editor is a good place to examine what's availabe because many text editors are able to import .tmThemes or use them directly (Sublime, VS Code). You can see here that the Monokai theme supports about 20 tokens and doesn't differentiate much between scopes: https://tmtheme-editor.herokuapp.com/#!/editor/theme/Monokai https://tmtheme-editor.herokuapp.com/#!/editor/theme/Monokai Personally, I prefer highlighters that do something to highlight variables differently, like this variant of Monokai (ie around line 45 for the JS example): https://tmtheme-editor.herokuapp.com/#!/editor/theme/Monokai%20Extended%20Mod https://tmtheme-editor.herokuapp.com/#!/editor/theme/Monokai...
- yoz-y 10y agoMany IDEs do that. For C++ i use Qt Creator which differentiates all of that and more (virtual functions, globals, primitive vs complex types etc)
- hvidgaard 10y agoThere is a lot of things we can do with highlighting, but that is not one that we should. An online linting tool should tell you that a variable is shadowing another (and I personally believe that it should not be possible at all). If you make a syntax highlighter that can color differently based on scope, you're only one stop away from a tool that can warn you about shadowing anyway.