Yet more Improvements to RSyntaxTextArea

January 10th, 2010

Happy New Year!  After a nice long break, it’s time to get the ball rolling on the Fifesoft projects again!

First, some low-lying fruit has been picked for RSTA.  You can now toggle whether end-of-line markers are rendered at the end of each line.  This can be useful for things such as seeing extra whitespace at the end of lines.  Here’s a preview of this feature being used in RText, where it is already integrated in SVN:

EOL Markers in RSyntaxTextArea

EOL Markers in RSyntaxTextArea

Also, and perhaps more importantly, there have been improvements in RSTA’s keyboard navigation.  Ctrl+left/right arrow have always skipped words, but until now, it’s used Java’s default “word skip” behavior (e.g. BreakIterator.getWordInstance()).  This isn’t really optimal for skipping “words” in source code, so this functionality has been revamped to behave like Eclipse does.  The only difference is that the caret does not stop at capital letters in camelCaseIdentifiers.  I despise this behavior, and I don’t know why the Eclipse devs think it’s a good idea.  Besides this, double-clicking on a word does a better “select word” for source code than before.  These are little things that make a big usability difference.

Finally, external tool support is being added into RText.  This will allow you to run things such as Ant, compilers, or whatever else from directly inside RText.  Nothing really to show at the moment though, just the framework has been put in.

Java Field and Local Variable Completion

December 10th, 2009

The Java code completion I’m working on has hit a new milestone.  Code completion for fields and local variables is starting to work:

Field Completion

Field Completion

RText 1.0.0 Released!

December 5th, 2009

It’s been a very long time coming, but RText 1.0 has finally been released!  Since it’s been production quality for awhile now (I’ve used it at work, across multiple OS’s, for years now), I decided to give it the credit it deserves.

Cool stuff in the 1.0 release include:

  • Cleaned up the main window – removed some unnecessary borders around components (Swing is bad at that sort of thing), and modernized the appearance of “dockable windows” (the windows the plugins live in).
  • Updated to the latest RSyntaxTextArea release.  This brings highlighting support for Scala, Delphi and BBCode, auto-insertion of closing curly braces in C-style languages, auto-completion of closing tags in XML, and a default color scheme that’s easier on the eyes for markup languages.
  • A spell checker was added.  It uses Jazzy and supports American and British English out-of-the-box.  Spelling errors are squiggle-underlined, and a focusable tool tip allows the user to correct the spelling error, add the word to a user dictionary, or ignore the word (just like in Eclipse).  I’m particularly proud of this new feature.
  • An optional “Tasks” window displays all instances of “TODO” and “FIXME” in your code comments for all opened files, like in Eclipse.
  • The file chooser now lets you open files in the system default viewer or editor via RMB -> Open In… -> System Viewer/Editor.  This feature requires Java 6.
  • Improved the “Split Window” view.  While the default is the Tabbed View, “Split Window” is probably the second-most popular view in RText.  The file list is now a real “dockable window” so it integrates into the rest of the UI like it’s supposed to now.  It also now has a context menu for the files in it (save, close, file properties, etc.).
  • Big code reorganization that doesn’t really show in the application itself, but hopefully makes the source a little better organized.

There’s plenty to do for 1.1, not the least of which is to bring some of the localizations back up to date (they really fell behind with this release).  I also plan to add “External Tool” support – assign a keyboard shortcut to your favorite application!

Give it a try and see what you think!  Feedback, criticism, and everything else is welcome in the forums.

RSyntaxTextArea 1.4.0 Released! SpellChecker Too!

December 2nd, 2009

Both RSyntaxTextArea and SpellChecker 1.4.0 were just released on SourceForge!  Go grab them and try them out!  A lot of new features and bug fixes have gone into the library with this release.  Spell checking alone has been an oft-requested feature, but there’s lots more than that:

  • “FocusableTips” were added, which are tool tips that become focusable when the
    user clicks on them or presses F2, like the tool tips in Eclipse.  These
    are the default tool tips for RSyntaxTextArea, and can be used by parsers
    (such as the spell checker) for user-friendly assistance.
  • Added an “Error Strip” component, designed to sit on the right-hand side of an RSyntaxTextArea.  Also seen in Eclipse and NetBeans, this component is capable of displaying colored markers for various stuff in the editor – parser errors, marked occurrences of the currently selected identifier, etc.
  • Delphi, Scala and BBCode syntax highlighting were added.
  • RSTA will now automatically insert a closing curly brace when appropriate for C, C++, C#, Java and Perl.  This behavior is toggle-able in the API if you don’t like or want it.
  • RSTA will also now automatically complete closing XML tags when “</” is typed (again, you can turn this off if you don’t want it, but it’s really nice!).
  • Various bug fixes and improvements.
  • The spell checker library is now officially released.  It’s version is “1.4.0″ to indicate that it should only be used with RSyntaxTextArea 1.4.0, not earlier releases.  It comes with a simple demo app showing how easy it is to use it with RSTA.
  • RSTA comes with a “Task Parser” as well.  It scans source code for the tokens “TODO” and “FIXME” in comments.  Applications can use this parser to provide the user with a list of “tasks” they’ve reminded themselves of in code.

Now that the release is done, I plan on updating the RSyntaxTextArea site with documentation on how to use these cool new features.

Also coming up shortly, a new RText version should be released that will take full advantage of all of these new features!

Java Code Completion

November 15th, 2009

To ensure the robustness of the AutoComplete library, I decided to see what it would take to implement some basic Java code completion.  This is of course much more complex than completion for markup languages, and presents a different set of challenges, but it’s something I’ve always been interested in.

The first thing that I needed was a Java parser, one that could break a source file down into an AST suitable for code completion.  This means you don’t have to go as far as parsing actual method bodies, you just have to grab imports, class/interface/enum names, method and field names, and local variables.  Of course, this isn’t a trivial task by any means; especially for local variables, you have to parse method bodies “well enough” to be able to get the variable names and types, without getting caught up in validating the method body’s structure.

Luckily, I had already been working on such a beast off and on (yes, I’m a geek) so I had something to go on.  It can currently parse all source files in the 1.6u16 JDK (well, classes and interfaces, I’ve put off enums for now to work on other areas), so I think it’s in pretty good shape.  Its error recovery (ability to keep parsing after seeing invalid Java source) is pretty terrible, mostly due to my lack of real education in parsing/compiler design.

So with the Java parser at least functional, the next step was to integrate it into RSyntaxTextArea’s Parser API.  That way the parser runs whenever the text component’s document is modified, allowing the user to get up-to-date completion choices automatically.  This part was easy, as RSTA’s Parser API was already up to the job.

Here’s what’s included in completion suggestions so far:

  • Field and method names for members of the class being edited.
  • Field and method names for all super classes and implemented interfaces.  Access flags are honored – e.g. you will not see suggestions for private members of extended classes.
  • Local variable names for variables accessible at the current caret position.
  • Names of imported classes (e.g. “import java.io.*;” allows everything in the java.io package to be suggested).  Again, access flags are honored – package private classes, etc. are not suggested (unless the source being parsed is part of that package).
  • Anything fully-qualified is suggested as well, so typing “com.sun.java.swing.<ctrl+space>” will suggest everything in that package, whether you’ve imported it or not.
Java Code Completion

Local Variable Completion

Completion of a local (marked deprecated) method

Completion of a local (marked deprecated) method

Handling Fully-Qualified Class Names

Handling Fully-Qualified Class Names

Of course, this is no Eclipse (yet!), so there’s plenty of issues to work out:

  • It can be slow when loading classes from imports of large packages the first time(e.g. importing java.util.*, java.io.*, javax.swing.* all together).  Once the classes are loaded, code completion is fast, it’s just the initial caching that can take some time.  This is because this package actually parses the completion info out of the jar (e.g. scans the .class files in a tools.jar), which can take some time.  We should be smart and load this stuff off the EDT when possible (e.g. when the user adds the import, but before they hit ctrl+space).
  • It does not yet offer available methods for local variables or members.  For example, for the local variable “String str”, typing “str.get<ctr+space>” will not return “getBytes()”.  The parser does know that “str” is a String however, so this functionality is on the to-do list.  This could get very complicated however, with situations such as chained methods.
  • Javadoc is not served up with the completion choices.  This can also be added, but probably won’t be seriously looked at until other issues are sorted out first.  Expect to see Javadoc returned for members in the being-parsed source before general purpose, src.zip-style documentation support.

Markup Language Enhancements in RSTA

October 13th, 2009

I decided to give the markup languages (XML, HTML, JSP and PHP) a little love  in RSyntaxTextArea.  Their syntax is so structured it should be easier to support more advanced features with them than with more abstract languages.

The first thing I did was “soften” the default color scheme used for markup languages.  Here’s how an HTML file looks out-of-the-box now:

Softer color scheme

Softer color scheme

Note that element names are now differentiated from attributes.  I may end up softening the string color as well, as that’s still a little obnoxious.

With things looking nicer, I decided to implement a new time-saving feature.  Now, typing “</” in an XML file will automatically complete the closing tag with the correct tag name.  e.g. typing:

<foo></

will type the following into the editor:

<foo></foo>

A welcome time-saver.  This feature can also be toggled on with HTML, JSP and PHP, but by default it is off, due to HTML often accepting unclosed tags such as <p>, <hr>, etc., which would mess up close-tag completions.

Going one step further from completing closing tags, I also used the AutoComplete library to add auto-completion for HTML, JSP and PHP.  The completion is very smart:

  • It only offers tag names as suggestions when you’re at the start of a tag (e.g. “<” or “<ht”).
  • If you’ve already typed a tag name, only the attributes valid for that tag will be offered as completion choices until the tag is closed.
  • No completion choices are offered if it doesn’t make sense (you’re in a comment, a string literal, in embedded JavaScript, etc.).
Auto-completing an HTML tag

Auto-completing an HTML tag

Intelligent attribute completion

Intelligent attribute completion

HTML/JSP/PHP code completion will definitely be integrated into the next RText release, but I’d like to figure out a way to release it alongside the standard AutoComplete library.  I don’t think it should be a part of the main library itself (why bloat the library with completion support for a language that might not be needed by all users?), but perhaps some kind of additional jar, that includes pre-built support for certain languages such as this?

If anybody would like to help filling in the gaps in the description for HTML tags and their attributes for this HTML code completion, get in contact with me.  I scraped some basic info off the web, but it’s really lacking.  You would of course receive credit for your input.

Breadcrumb Bar Nearly Done

October 4th, 2009

The breadcrumb bar I blogged about earlier is nearly done.  I managed to mimic the behavior seen in Vista’s breadcrumb bars, clicking outside of the “button” area turns the breadcrumb bar into a text field for manually typing a file path.  Even better, it offers suggestions as you type!  Here’s how it’s looking in RText’s file chooser dialog:

Using the Breadcrumb Bar

Using the Breadcrumb Bar

Morphing into text field with autocomplete

Morphing into text field with autocomplete

This is much more powerful than the combo box with the directory hierarchy that was there previously.  Note that if too many folders are in a directory to be listed in a single menu, there are arrows at the top and bottom of the menu, allowing you to scroll through the entire list.  The menu also responds to the scroll wheel on the mouse.  I’ve seen this behavior on OS X, on a Macbook where screen space is limited (or you just don’t want a menu to get too long).

This component should honor RTL locales, as well as look good in all LookAndFeels (tested in all the standard ones, including Nimbus, which, as always, took a little work to get looking good).  As always, check it out from RText’s Subversion repository if you want to see how it is implemented.

TokenMakerMaker Beta available for testing!

September 26th, 2009

Though development has unfortunately come to a crawl, a first beta of TokenMakerMaker is available for testing.  Contact me if you’re interested in testing it out.  It will be a feedback-driven project – features that are asked for are what will be implemented.  I plan on using it to generate a few new scanners for the next version of RSTA – first will be ActionScript.

Breadcrumb Bar in RText

September 12th, 2009

Progress has been very slow the last couple of weeks, unfortunately, but there has been a little bit of work going on.

The most exciting thing is definitely the addition of a breadcumb bar to RText’s file chooser.  The appearance of this component tries to mimic Vista’s breadcrumb bar in Windows Explorer.  Things are looking good so far:

Breadcrumb Bar

Breadcrumb Bar

It still needs to handle runtime LaF changes properly, however.  I’m also toying with having it “transform” into a text field when you click on any empty space at the end of the component, like Vista does.  On an Enter keypress (or focus lost), it morphs back into a breadcrumb bar.  It’s a very nice feature.  Check out the current progress in SVN.

Besides that, not much has happened, save for some small progress on TokenMakerMaker.  I’ll be sending a preview to those interested in testing it very soon hopefully.  I also plan to eat my own dog food, and use it to generate some TokenMakers for new languages for the next RSTA release!

“TokenMakerMaker” – Easy creation of custom syntax highlighters for RSTA

August 22nd, 2009

I’ve gotten several requests asking for the ability to add syntax highlighting for custom languages to RSyntaxTextArea.  Because of the way it is designed, RSTA doesn’t lend itself well to this type of thing.  Creating a highlighter that just read through a properties file (or XML) and highlighted stuff via regular expressions would probably not perform well enough for most people.  But the learning curve for how to hack at JFlex-generated output so that RSTA is happy with it is also rather high.

So I’m working on a new tool, called, for lack of a better name, “TokenMakerMaker” (name suggestions are welcome!).  RSTA has uses a TokenMaker class to know how to highlight for a given language, such as Perl or Java.  TokenMakerMaker is a GUI program that allows you to enter the specifications for your language – keywords, comment delimiters, data types, etc.  It can take that input and generate the JFlex input file for your TokenMaker, as well as the actual Java source for your TokenMaker (it’s hooked into JFlex).  Further, if you’re running TokenMakerMaker with a JDK, as opposed to a JRE, it can compile the Java source generated and allow you to test it out in an RSyntaxTextArea instance, at design time!

This tool is nice because the generated scanners will be extremely fast (optimized by JFlex).  In fact, they should be every bit as fast as the scanners that come built into RSTA.  The key will be making the UI give as many options as possible so that what a generated scanner can do isn’t too rigid.

To test it out, I’m using it to generate a (simplified) TokenMaker for Java.  How is it looking so far?  Well…

Here’s a screenshot of the panel allowing you to define the comment delimiters:

Defining the comment delimiters for Java in TMM

Defining the comment delimiters for Java in TMM

And the panel allowing you to define the data types:

Defining the data types for Java

Defining the data types for Java

And here’s the testing window you get after clicking “Generate”:

Testing our generated Java TokenMaker scanner

Testing our generated Java TokenMaker scanner

It’s still early on but I hope to have a few people test it out soon.  Here’s what’s left to be done:

  1. Flesh out the UI
  2. Add panel for defining standard library functions
  3. Add more configurability for Strings (escapes allowed or not, etc.)
  4. Allow saving TokenMaker definition to XML.  Create batch tool to generate .flex/.java directly from XML to facilitate automation of the process

If you’d like to try this tool out early and provide feedback, let me know!