5 ms·
JavaScript Scope Context Coloring
- druska 14y agoNow we just need a Sublime Text plugin for this.
- LAMike 14y agoLet's make a Kickstarter
- dag11 14y agoThis is great. Idea: Implement loose "syntax" highlighting over the scope highlighting by bolding syntax keywords instead of highlighting them. Perhaps also slightly change the brightness of certain syntax keywords.
- crazygringo 14y agoGreat idea. Bolding language-specific words, and then making strings and comments less bright, would probably achieve 90% of the usefulness of normal syntax highlighting, and combine well with this.
- scjr 14y agoIt might be better to use variations in the background color. It may feel more natural to do so and it would allow normal syntax highlighting alongside scope highlighting.
- solox3 14y agoIt is a good idea indeed. I believe Notepad++ does background scope highlighting already, just not accurate enough for JavaScript specifically.
- archangel_one 14y agoI was just thinking the same; when all my syntax highlighting in a region looks backwards, I normally assume I've got a mismatched quote just before it. I think I'd be thinking that with this all the time. Subtle changes in the background colour would be a nice alternative.
- seanp2k2 14y agoYes; highlight BG lighter grey. This would be an awesome plugin for ST.
- Zecc 14y agoMake the background color become less contrasting with the foreground color the more you nest. The larger the number of nested scopes, the harder it's going to be to read it anyway! I'm actually serious by the way.
- ufo 14y agoAnother possibility might be just colloring variables and assignments (since thats where the scoping actually matters)
- Mahn 14y agoExactly my thoughts, this could work really well if implemented properly.
- necolas 14y agoEver since watching that Crockford talk, I've wanted to try this out as a Vim plugin.
- curiousdannii 14y agoIt doesn't seem to handle comments correctly. I need to delete all mine to make it work.
- nadinengland 14y agoI noticed that too. It also only highlights variables from other scope once per function which is a tad odd but for experimental you can't complain!
- ebiester 14y agoI think this would make a lot of sense for Lisp or Clojure, at least when starting out.
- martinced 14y agoClojure puts the emphasis on functional programming and the context should hardly ever be "global". So I don't think it would make much sense: the context is the sexp you're currently in (recursively of course) and that's it. Sure it may help a bit if you're inside, say, a let and have a "long" function: so you'd be on a "var" (they're not vars but bear with me) and that same var would be highlighted inside the let. Why not but... You do know anyway that it cannot come from anywhere else because you shouldn't be using globals in the first place. I do certainly try to only write referentially transparent Clojure function so this kind of coloring really wouldn't help me a lot. Now of course there is an Emacs minor-mode which does modify the background of each sexp recursively inside your function should you like such a thing. (I'm personally fine with indentation and rainbow parentheses but YMMV)
- wavesounds 14y agoReally great idea, would be super useful, it looks like its still got a ways to go though, it doesn't seem to recognize global variables yet for one http://stackoverflow.com/questions/235360/what-is-the-scope-of-a-function-in-javascript-ecmascript http://stackoverflow.com/questions/235360/what-is-the-scope-...
- Kudos 14y agoIf you're using strict Javascript (and you should be) there are no implicit global variables.
- riffraff 14y agohow would an example of javascript without implicit global variables work? For example, how does it get access to "Array", "require" or "window" ? (I don't think "use strict" goes to the length of turning javascript into bracha's newspeak but I may likely have no idea what "strict javascript" actually refer to)
- mostlystatic 14y agoYou can access global variables as normal, but you can't implicitly declare them by doing `myGlobaVar = 5` - you have to use `window.myGlobalVar`.
- TheFuntastic 14y agoCan anyone point to which particular crockford talk this was inspired by? I've had the idea for scope highlighting bashing around my head for a while now, would love to know more.
- jnotarstefano 14y agoIt's from "Monads and Gonads", a talk delivered at YUIConf 2012. Here it is: http://www.youtube.com/watch?feature=player_embedded&v=dkZFtimgAcM#t=15m58s http://www.youtube.com/watch?feature=player_embedded&v=d...
- TheFuntastic 14y agoMany thanks!
- davvid 14y agowow, you did it! https://news.ycombinator.com/item?id=5095837 https://news.ycombinator.com/item?id=5095837
- VeejayRampay 14y agoI'm really surprised this talk didn't generate a PC outcry given all the mentions of "huevos", "gonads" and the likes...
- deleted 14y ago[deleted]
- Vivtek 14y agoThis is probably one of those things that's really effective if you have working color vision, right?
- macca321 14y agoI forked it with fonts: http://snag.gy/TnNBO.jpg http://snag.gy/TnNBO.jpg Maybe not so useful...
- arianvanp 14y agoDiscussions between developers will be so much more jolly :) "Dude, why isn't my `this` in the comic sans scope referring to the DOM D:"
- seanp2k2 14y agoWhat if it changed based on cursor position?
- phy6 14y agoWow, I'd love to have this in a Java IDE. I often have to deal with reverse engineering amateurish code in many 1000 line classes.
- mateuszf 14y agoActually Intellij Idea has the same concept, here it is working in HTML: https://dl.dropbox.com/u/456905/idea.png https://dl.dropbox.com/u/456905/idea.png I think it would be great if they added it to JS, with their powerful syntax parsing it would be probably trivial to do. Edit: probably works in their php, django and rails ide-s.
- jtreminio 14y agoPhpStorm has this ability - and I've turned it off. Too much colors for my blood, and it doesn't look good against Solarized. One thing I really enjoy about this IDE is the indentation level markers - basically lines draw down to show you where the current scope ends (braces, parens).
- efnx 14y agoSomeone should abstract this out (for an arbitrary number of languages) into a program that would provide annotations for vim or emacs or...
- VeejayRampay 14y agoThat's excellent. A nice variation around this that I've been keen on for a long time and have been wanting to see in modern IDEs is using 3D (or drop shadows) to simulate the nesting of blocks/closures/scopes and give the programmer an instant understanding of the different levels and depths.