RSyntaxTextArea now supports syntax highlighting and code folding for D. Nestable comments are handled properly. The screenshot below shows some of D’s unique syntax features:
Archive for the ‘Code Folding’ Category
Syntax highlighting and code folding has just been added for Dart. Dart aficionados, clone the RSTA repo and let me know if I’ve missed anything with the highlighting!
Because I haven’t had much time to work on RSTA lately, I’ve been thinking about making a list of work items in an attempt to get motivated. So here’s what’s on the list so far for the next RSTA release:
- Performance improvements, particularly for word wrap with very long lines. This has been asked for a couple of times in the forums. I’ve done some work, that will be available in the next SVN commit, that will improve performance to some degree. One of RSTA’s primary issues here is that modelToView()/viewToModel() calculations are relatively expensive, and for very long word-wrapped lines, they are called literally dozens of times whenever text is inserted or the window is resized. As a first pass, I’m refactoring things a bit so that the data used by these method calls is cached much more aggressively; this seems to improve things quite nicely. Moving forward, I might also try to minimize the number of calls to these methods in general, though that will be a more difficult task. There were also some performance improvements made to WrappedLineView.java in the JDK, around the Java 5 timeframe, that RSTA may be able to learn from/graciously borrow.
- Syntax highlighting for R.
- Syntax highlighting for .htaccess files.
- API in AutoComplete libarary to specify the expected type of arguments in a parameterized completion.
Any other suggestions?
Also, support for NSIS scripts has been added. I’m sure most developers are familiar with NSIS, which makes it super easy to create installers for your Windows applications. RSTA now supports full syntax highlighting and code folding for NSIS scripts:
The second beta of 2.0 was just released on SourceForge. This beta makes folding work when word wrap is enabled, fixes some keyboard shortcuts that didn’t work quite right around folded regions, and a few other minor things. Check it out!
There are a few more things I’d like to do before a final 2.0 release, but they’re pretty minor. The battle plan includes:
- Folding should recognize XML comments.
- API to do find/replace in selection (not just next/previous from caret or all).
- A couple of more token types (again).
- A way for users to disable the fold indicator tool tips for collapsed fold regions.
- Profile performance of common operations when code folding is enabled, make sure there aren’t horrible degradations caused by the code folding code.
As always, please please please start using code folding ASAP and let me know of any issues you find!
As I know that some folks aren’t too keen on always grabbing bleeding edge code from Subversion, I decided to make a “beta” release of RSyntaxTextArea 2.0 available on SourceForge as well as tagged in SVN. I hope that releasing in jar form will help facilitate more folks using it and providing feedback.
Just as a recap, the major changes in this release currently include:
- Code folding for C, Java, Perl, XML, MXML, and other languages (currently only available when word wrap is not enabled).
- Theming support via XML. This allows for easily customizing RSTA to fit the color scheme of your application, easier saving/loading user-defined token styles, etc.
- A few new token types to allow for better lexing/token highlighting.
I’d like to make another call to action here, and ask everyone interested to try out the code folding support in their applications today! Assuming you’re editing a language that supports it, it should be as simple as this:
The demo application in SVN provides a concrete example of this option in use.
Please report any and all problems you find in the RSTA forums!
Finally, I’d like to mention that I’ve gotten several emails that included patches with new features lately. If you’re one of those folks, I’d just like to let you know that I am interested in what you’ve sent, I just haven’t yet gotten around to looking at it and working it in if/where possible. Feel free to email me again if you want, but even if you don’t , I’ll (hopefully) be responding soon!
I’m still making progress with code folding support in RSyntaxTextArea. Several visual bugs were squashed (current line highlight, matched bracket painting when toggling folds), as well as a couple of “real” issues with the functionality. The coolest thing that’s been added is folding support for XML:
Again, the actual rendering of the folded lines (color, the annotation at the end, etc.) is subject to change. There are now also ways to do various folding stuff in the editor’s popup menu:
I’ll give these actions keyboard shortcuts moving forward, like those for Cut, Copy, etc.
Finally, note that, for any folded region, hovering the mouse over the “+” icon gives you a preview of the folded section, over-top where it would be in the editor:
Unfortunately, Ctrl+Print Screen in Windows doesn’t capture the mouse pointer, but you get the point!
Again, please try all this out by grabbing the latest from SVN! Just call “textArea.setCodeFoldingEnabled(true)” and start tinkering with it. Let me know any and all bugs you find!
Check out the lastest from Subversion to try out the WIP code folding in RSyntaxTextArea. Simply call:
The fold indicator will be added to the gutter, and fold markers will appear where appropriate. Currently supported languages include:
- C, C++, C#
For other languages, there is no fold parser, so the editor won’t behave any differently than it used to (or shouldn’t!). For the languages above, code blocks and multi-line comments are fold-able. For Java, all import statements are also grouped together into a fold-able region. Folding only currently works when line wrap is disabled – you won’t get any fold indicators if you enable word wrap.
Check it out and give it a go, but please keep in mind that this is an alpha feature! There are likely lots of bugs. Please report ’em either by replying to this post or, even better, by posting them in the forums.
Also, I’m still playing around with the appearance of folded lines. The little icon-ish thing at the end of folded lines (a la NetBeans) is temporary and probably won’t exist in the final version. I’m trying to decide whether coloring the background of folded lines looks better than simply drawing a line across the editor.
I told myself I’d never do it, and it’s a feature I personally never use. Some people agree with me, as evidenced by the second hit on Google for “code folding.” Still, lots of people like it, and so in an effort to make RSyntaxTextArea as robust as possible, I’ve begun exploring code folding:
Nothing is checked into Subversion yet, but I’ve taken the first baby step. Folding is done by a FoldParser interface implementation, so languages with differing ideas of what a “foldable region” is can be accommodated. A “CurlyFoldParser” implementation will be available by default, that simply identifies foldable regions by curly braces (seen above). This should be sufficient for the many languages out there with C-like syntax. I already have several ideas to allow for easy extensibility as well, as far as fold parsing is concerned.
The FoldParser for a text area is called after a short time of no edits, similar to other RSTA Parser implementations, such as the built-in TaskTagParser and the SpellChecker add-on. Folds are re-evaluated, and the fold indicator in the gutter is updated if necessary.
Of course, there are all kinds of crazy edge cases you never think about until you start implementing something – two or more folds starting on the same line, one fold starting on a line in which another ends, etc. I’m looking into how other editors handle such cases, and you’d be surprised how sometimes they aren’t as well-behaved as you’d expect (which is good for me, as I can copy their behavior and say things like “Well, Eclipse behaves like that!”).
In any case, this means that I’ll need folks willing to beta-test this feature before it’s included in an “official” RSTA release. If you’re a user of RSyntaxTextArea and are ga-ga about code folding, please let me know and we’ll work together to make sure this feature is as bullet-proof as possible!