Archive for the ‘RSyntaxTextArea’ Category

RSyntaxTextArea 2.0.1 Released

Sunday, February 19th, 2012

All “.0″ releases have an obligatory follow-up maintenance release.  Grab RSyntaxTextArea 2.0.1 from SourceForge or Subversion today!  This release fixes the two following things:

  1. If SearchEngine selects text as part of a search/replace operation, and that text in a collapsed fold, the fold should be expanded to make the selection visible.
  2. The DTD for themes, theme.dtd, was not included in the 2.0.0 RSyntaxTextArea binary jar.  This made themes (one of the new features!) unusable since they could not be validated.

In addition, I made an API change.  I know it’s somewhat taboo to do that for minor releases, but it’s a straightforward change in your code to stay up to date.  This change is being made to support enhancements to the find/replace functionality in RSTA moving forward.

Previously, to do a find or replace operation in RSyntaxTextArea, you used one of the following methods from the SearchEngine class:

SearchEngine.find(JTextArea textArea, String text, boolean forward, boolean matchCase, boolean wholeWord, boolean regex);
SearchEngine.replace(JTextArea textArea, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord, boolean regex);
SearchEngine.replaceAll(JTextArea textArea, String toFind, String replaceWith, boolean matchCase, boolean wholeWord, boolean regex);

This is functional, but messy, and adding new options in the future would simply make the method signatures even longer (or introduce overloads).  To remedy this, I took a sip of the OO-KoolAid, and created a new SearchContext class.  This class keeps track of all information relevant to a find/replace operation.  The SearchEngine methods above now take a SearchContext instance as a parameter:

SearchEngine.find(JTextArea textArea, SearchContext context);
SearchEngine.replace(JTextArea textArea, SearchContext context);
SearchEngine.replaceAll(JTextArea textArea, SearchContext context);

This allows the searching API to stay clean, and adding support for a new search option is as easy as adding a new property to the SearchContext bean.  I hope to add support for at least two new search options in the future:  “search in selection” and “ignore comments.”

The actual SearchEngine class will likely be simplified as well.  Currently, it takes a different code path if you do a regex search than when you do a plain text search.  More code => more chances for bugs.  I’ll likely convert the plain text scenario into a regex one under the covers (convert your “find” text to a regex by escaping characters special for regular expressions).  This, along with making RSyntaxDocument a CharSequence, will greatly simplify the searching code, as well as provide a performance boost when searching large files.  All of this is implementation details of course, and won’t matter to someone just using the library.

Only RSyntaxTextArea has a 2.0.1 release.  AutoComplete, SpellChecker, etc. are still at 2.0.0 as they did not need any modifications.

RSyntaxTextArea 2.0.0 (final!) Released

Monday, February 13th, 2012

Enough with the betas!  RSyntaxTextArea 2.0.0 was finally released yesterday.  Folding appears stable enough and performance is good.  Editing a 400,000 line Java file with folding enabled does exhibit some delay while typing, but none while painting/scrolling – good enough for me!

Moving forward, focus will be shifted once again to code completion and RSTALanguageSupport.  JavaScript and Java completion both have work that needs to be done.  CSS highlighting also needs a little work (I never realized how complex CSS really is.  I’ve also had requests for “search in selection” and a few other miscellaneous features.  Any more suggestions for 2.0.1?  Post a reply here or in the forum!

The online Javadoc has been updated, and I’ll update the examples next.

 

JavaScript Language Support Updates

Monday, February 6th, 2012

First, a quick note that RSyntaxTextArea 2.0.0-beta3 is available on SourceForge!  Among other things, this release greatly improves syntax highlighting for JavaScript, HTML, PHP and JSP.

I promise RSTA won’t stay on this “beta” release track forever…

Anyway, there’s also been progress in the JavaScript language support.  It’s been in SVN for serveral days now, I just never got around to blogging about it.  Some of the “polish” I spoke of in my last post is now there:

JavaScript Improvements

JavaScript Improvements

Note the icons in the completion choices window and the outline tree on the left-hand side.  Clicking on an element in the outline tree selects that element in the editor, just like in the Java support.  We also now have Go To Member support:

Go to Member

Go to Member

Ctrl+Shift+O (Cmd+Shift+O on OS X) displays this popup allowing you to type/select the name of a variable or function to navigate to in the editor.

Here’s what’s coming up next with JS support:

  1. Take scoping into account when displaying completion choices.
  2. Use knowledge of variable types to provide better completion choices.
  3. Clean up JSDoc descriptions in the completion description window.

 

Minor updates

Saturday, January 28th, 2012

Nothing bad has been found with code folding yet – so far so good!  A few tweaks in other areas were pushed recently, the most important probably being a scanning bug in HTML and other web languages.  A JavaScript line comment (“// …”) should not hide a closing </script> tag.

If you’ve watched this blog for any length of time, you might have noticed that my motivation often shifts from one area of the project to another (new language highlighting, code completion, code folding, etc.).  Well, since code folding is winding down, I’m turning my focus back to code completion.  The wonderful Rhino project, along with more web programming at work, has motivated me to look into JavaScript code completion.

A few months ago, somebody emailed me stating that they were working on this very thing.  We were hoping to get his work integrated into RSTALanguageSupport at some point, but unfortunately I stopped hearing from him, and I can no longer find that email thread (!).  In any case, I decided to dig into this myself.  The good news is that Rhino has an incredibly easy-to-use API.  I literally read no documentation at all – just Ctrl+Space’d and picked out the classes it looked like I needed.  Fantastic!  In a short while I already had squiggle underlining of syntax errors and working completion for functions and variables:

JS Code Completion - Day 1

JS Code Completion - Day 1

It’ll look prettier when it’s done of course; this is without any polish.  This will be made just as robust as the current Java language support, but with full syntax checking (Java currently doesn’t check for syntax errors in method bodies).  This should include both an outline tree component as well as Go to Member support.

I should also hopefully get off my bum and get back to work on the Java support.  When I do, I’ll be picking up where I left off, improving parameter completion (determining variables in scope of the right type/subtype for a parameter and suggesting them).

RSyntaxTextArea 2.0.0-beta2 Released

Saturday, January 14th, 2012

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!

RSyntaxTextArea 2.0.0-beta1 Released

Saturday, December 24th, 2011

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:

  1. Code folding for C, Java, Perl, XML, MXML, and other languages (currently only available when word wrap is not enabled).
  2. 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.
  3. A few new token types to allow for better lexing/token highlighting.
  4. Updated syntax highlighting for some languages, especially PHP and JSP (which both previously had a couple of issues with JavaScript 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:

textArea.setCodeFoldingEnabled(true);

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!

 

Java: Go to Member

Monday, December 19th, 2011

One feature currently in the JavaLanguageSupport is “Go to Window”.  Pressing Ctrl+O (I know, needs a different shortcut) pops up a tool tip-ish window with a tree view of the members of the current source, just like in Eclipse:

Go to Member

Go to Member

At the top is a text field.  Typing in this field filters what members are visible in the popup on the fly:

Filtering while typing

Filtering while typing

Selecting a member in the window selects that member in the editor:

Making a selection

Making a selection

Once you start using this feature, you’ll never stop using it.  It’s much faster than manually scrolling through source code!

While only about 80% of the way there, this functionality will of course be broken apart from the Java language support in particular, so it can be used by other languages.  Unfortunately Java is the only one for which I’ve created a parser capable of finding the members in a source file.  I’ll probably move the ctags support from [url=http://fifesoft.com/rtext/]RText[/url] into RSTALanguageSupport just for this.

Theming Support in RSyntaxTextArea

Monday, November 14th, 2011

One cool new feature in the upcoming release of RSyntaxTextArea is theming support.  Currently, if you want to customize the fonts and colors used in RSTA, you have to programmatically use the SyntaxScheme and Style classes to do so.  This is actually very straightforward, but it also means you have to design your own UI if you want your users to be able to customize the editor in your application.  Many folks (not me :)) would find such a task tedious.

In the next release (and available for a preview in SVN), you’ll be able to completely customize RSTA via an XML file.  This allows you to externalize your customization logic from your application, and even deliver various “themes” if you so desire!

Theme XML is validated against the new theme.dtd.  You’ll notice that it allows you to set not only the fonts and colors used in the editor, but also those used by the gutter (assuming RSTA is wrapped in an RTextScrollPane).  There are a few sample themes already in the RSyntaxTextAreaDemo project.  These will probably get added to the main RSyntaxTextArea project, but won’t be a part of the actual library jar to avoid any more bloat.  Applications can feel free to ship these themes as-is, or modified, with themselves.

Using a theme couldn’t be simpler using the new Theme class:

   InputStream in = getClass().getResourceAsStream("/dark.xml");
   try {
      Theme theme = Theme.load(in);
      theme.apply(textArea);
   } catch (IOException ioe) {
      ioe.printStackTrace();
   }

Saving a Theme will be added once I have everything configurable via the XML.

Here’s an example of the “dark” theme currently checked in:

Dark Theme

Dark Theme

Code Folding Progress

Saturday, October 29th, 2011

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:

XML Code Folding

XML Code Folding

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:

New Context Menu Items

New Context Menu Items

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:

Folded Content in Tool Tip

Folded Content in Tool Tip

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!

Code Folding alpha added to SVN

Saturday, October 8th, 2011

Check out the lastest from Subversion to try out the WIP code folding in RSyntaxTextArea.  Simply call:

textArea.setCodeFoldingEnabled(true);

The fold indicator will be added to the gutter, and fold markers will appear where appropriate.  Currently supported languages include:

  • C, C++, C#
  • Java
  • Groovy
  • Perl

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.

Enjoy!