Archive for the ‘AutoComplete’ Category

Template Completions

Saturday, June 30th, 2012

A new feature has been added to the AutoComplete library trunk, and will be in 2.0.4 when it’s released:  template completions.  Equivalent to JDT’s editor templates in Eclipse, templates are an easy way to insert (usually, but not required) parameterized code into RSTA.

A common use case for TemplateCompletions is for inserting boilerplate code.  Take for example a for-loop that iterates through an array in Java.  The code always has the following structure:

   for (int i = 0; i < array.length; i++) {
    <cursor>
   }

The only thing that changes (sans formatting) is the name of the index variable and the name of the array being iterated through.  The ending cursor position should be inside the curly braces so the user can insert code into the looped-over code block.  TemplateCompletions provide a simple syntax for creating a code completion choice for inserting such a construct:

   String template =
      "for (int ${i} = 0; ${i} < ${array}.length; ${i}++) {\n\t${cursor}\n}";
   Completion tc = new TemplateCompletion(this, "for", "for-loop", template);

As you can see, a TemplateComletion takes a String representation of the code to be inserted.  Parameters are represented by substrings with the format “${foo}”.  These parameters are replaced by the user, similar to parameters in FunctionCompletions.  For parameters listed more than once in a template, only the first one can be edited by the user; during editing, all subsequent parameters with the same name will be automatically replaced with whatever the user types.

Parameters are cycled through via pressing Tab and Shift+Tab, or just by using the arrow keys.

The special parameter “${cursor}” denotes where the cursor will be placed upon pressing Enter or otherwise exiting template completion mode.  Specifying more than one ${cursor} in a single template results in undefined behavior.

Here’s an example of the above template actually being used:

Selecting the TemplateCompletion

Selecting the TemplateCompletion

Upon selecting the for-loop TemplateCompletion:

Inserting a TemplateCompletion

Inserting a TemplateCompletion

Editing the first “${i}” parameter:

Editing parameters

Editing parameters

Tabbing to (or pressing Enter to move directly to) the cursor end position:

End cursor position

End cursor position

All of the colors involved in marking parameters, etc. are configurable by the new org.fife.ui.autocomplete.AutoCompletionStyleContext class.

What’s next for this feature?  Well, again following in the footsteps of Eclipse, you should be able to specify the “data type” associated with each parameter, if any.  The AutoComplete library could then use that information to present the user with parameterized completion suggestions as it currently does for FunctionCompletions.

 

 

RSyntaxTextArea 2.0.3 Released

Tuesday, May 1st, 2012

RSyntaxTextArea 2.0.3 was just released on SourceForge!  Here’s what’s new:

 

  • LaTeX syntax highlighting and code folding:

    LaTeX Support

    LaTeX Support

  • DTD syntax highlighting:

    DTD Highlighting

    DTD Highlighting

  • Fixed an issue with RTextScrollPane, allowing it to be used in NetBeans’s visual editor
  • Fixed a bug in cold folding under certain cirumstances
  • RSTA now has anti-aliasing enabled by default (previously you had to call setAntiAliasEnabled(true) yourself)
  • TextEditorPane now fires FULL_PATH_PROPERTY from its load() method like it does from saveAs().

Download it today!

RSyntaxTextArea & RText updated in Maven

Thursday, April 19th, 2012

Just a quick note that a user has kindly updated the RSyntaxTextArea and RText artifacts available in Maven:

http://search.maven.org/#search|ga|1|g%3A%22com.fifesoft%22%20OR%20g%3A%22com.fifesoft.rtext%22

As usual, please report any issues in the forums.

RSyntaxTextArea 2.0.2 Released

Wednesday, March 14th, 2012

RSyntaxTextArea 2.0.2 was released yesterday on SourceForge!  This release includes some good bug fixes, and is recommended for anyone ready and willing to upgrade.  Here are the highlights:

  • The license was changed from LGPL to modified BSD.  There are folks afraid of anything with “GPL” in the title, perhaps rightfully so, so now RSTA is using a non-viral license.  This also clears up any confusion about a user’s ability to use a modified version of the library.
  • Added a cool new keyboard shortcut: select some text, and pressing Ctrl+K/Ctrl+Shift+K (Cmd on OS X) is “go to occurrence” like in Eclipse.  A quick and easy way to traverse through all instances of specific text in the editor.
  • Ctrl+/ inserts line comments when editing JavaScript, to match the “insert line comment” action in many other languages.
  • Fixed performance issue: Pressing “End” to go to the end of a very long line (thousands of characters) is no longer slow.
  • Fixed bug: Icon row header should automatically move icons around when folds are expanded and collapsed.  This is very important for folks looking to implement custom Parsers that show error markers in the Gutter, for example.
  • Fixed bug: When going to a bookmark via Ctrl+F2/Ctrl+ShiftF2, we should ensure that any collapsed folds enclosing the bookmark are opened.  Previously, the caret would be moved to the line containing the next bookmark, even if it was in a collapsed fold.
  • Other small tweaks.

As mentioned, the RSyntaxTextArea, AutoComplete, and RSTALanguageSupport libraries are all under a modified BSD license now.  The SpellChecker add-on library had to stay LGPL due to its dependency on a modified version of Jazzy.  I don’t see this as a huge problem since folks using SpellChecker aren’t as likely to want to modify it as they would with say the main RSyntaxTextArea project.

Enjoy!

RSyntaxTextArea 1.5.2 Released

Saturday, August 27th, 2011

A minor update of RSyntaxTextArea and AutoComplete are now available on SourceForge and the Subversion repository.  Here’s what’s new:

  • Simplified the anti-aliasing API.
  • Java syntax highlighting updates to support Java 7 (binary literals, underscores in int literals).
  • Added an API to render tab lines (aka indent guides).
  • Fixed single-quoted strings in MXML.
  • Added miscellaneous keywords to Unix shell and Windows batch scanners.
  • Minor bug fixes.

Nothing earth-shattering.  The most noticeable update (and it’s not that noticeable, to me at least) is the anti-aliasing updates.  Not only is the API simplified (don’t know what I was thinking when I originally created it), but RSTA will now automatically pick the “best” anti-aliasing method to match the AA done by your OS, according to Java2D.  Font rendering has always been a sore spot for Swing applications, but with the later Java 6 updates, it’s actually gotten really, really good (at least on Windows).  Text rendering now (practically) matches that seen in native apps.  RSTA now handles specifying the AA hints the “right” way to look at nice as possible.

The next release will likely see more drastic changes, and will come along-side updates to the RSTALanguageSupport library as well.

JSP Code Completion

Tuesday, July 19th, 2011

Some degree of JSP code completion is working its way into RSTALanguageSupport.  Currently only code completion/inline documentation for the standard JSP tags are baked in, but coming soon will be support for importing taglibs.  The code is actually mostly there; the problem is figuring out how to expose it in the API in a simple, clean way.  It’s a little tough since RSTA is just a text editor component; for an editor application with the concept of a project or workspace, things would be a little easier.

As with HTML code completion, only attributes appropriate for the tag at the caret position are suggested.

JSP Code Completion

JSP Code Completion

Java Code Completion Updates

Friday, June 24th, 2011

A couple of minor fixes to Java code completion support in RSTALanguageSupport have just been added:

1. Member completion for string literals has been added.  If you’re like me, and are a fan of putting String literals first in string comparisons, i.e.

   if ("PROPERTY_FOO".equals(value)) {
     // ...
   }

then you can see this feature in action.

String Literal Code Completion

String Literal Code Completion

2. Fixed a bug where, if multiple local variables of the same type were declared, and some initialized, in the same statement, some of them would not get parsed.  In the example below, “two” and “three” were not parsed previously, but now they are.

Multiple grouped local var declarations

Multiple grouped local var declarations

Many consider declaring variables like this to be poor form, but it’s valid syntax nonetheless, so the parser should handle it properly!

RSyntaxTextArea 1.5.1 Released!

Friday, March 25th, 2011

RSyntaxTextArea and AutoComplete 1.5.1 have both just been released on SourceForge!  This is a maintenance release, fixing minor issues and adding a few small improvements here and there.  Changes in this release include:

  • Fixed bug in properties file highlighting’s handling of single quotes.
  • Improvements to Windows batch file highlighting.
  • Adding a few more shell commands to Unix Shell syntax highlighting.
  • Fixed bug when pressing Enter at the start of an MLC or documentation comment in some C-style languages.
  • Changed “dumb complete word action” from shift+space to ctrl+enter, to eliminate annoying accidental activations.
  • Added a license header for those files that didn’t have one yet.

The SpellChecker library is still at 1.5.0.  All RSTA add-ons in the “1.5.x” family should be binary compatible with one another; just use the latest release of each (1.5.1 of RSyntaxTextArea and AutoComplete, 1.5.0 of SpellChecker).

Generics support added to Java Code Completion

Sunday, January 23rd, 2011

Support for generics (added in Java 5) is something that was sorely lacking from the Java code completion in RSTALanguageSupport.  That is, until the latest Subversion changes!  This is a very early implementation, and like a lot of the recent Java support changes, there may be bugs and performance issues.  But it’s there!  And things look good for simple usage of the java.util Collecitons classes:

Generics Support

Generics Support

Previously, methods such as List#add() and List#get() would always say that their parameter/return types were of type Object.  Now, if you specify type arguments to classes that accept them, code completion will reflect those type arguments.

As before, please be bleeding edge, try this out, and report back bugs!  You can do so either here, or in the RSyntaxTextArea forums.  There is also currently no way to turn this feature off (i.e. if you want to program with “-source 1.4″ effectively enabled), but that will come soon.

RSyntaxTextArea 1.4.2 Released!

Monday, August 2nd, 2010

Last night, RSyntaxTextArea 1.4.2 was released on SourceForge!  That includes new releases of RSyntaxTextArea as well as AutoComplete and SpellChecker.  This release was mostly about bug fixes and improvements in code completion behavior.  Here’s a quick list of all of the changes in this release.

  • Groovy syntax highlighting updates (GDK Object methods, Java 5/6 java.lang classes, URL’s in comments)
  • A fix to prevent security exception when setting AA hint in an applet (thanks to Frederic in the forums)
  • Fixing positioning of FocusableTips and code completion windows on multi-monitor setups (thanks to grzlbrmft in the forums for the bug report and testing).  I’m personally jealous of everybody out there with a dual monitor setup, who got to experience this bug.  :)

    AutoComplete Windows

    AutoComplete Windows

  • AutoComplete’s description window now updates itself in response to a selection change after a small delay (120ms) instead of immediately, to help performance for language supports with slower descriptions (e.g. file IO).  This mimics Eclipse’s behavior.
  • Added ActionScript syntax highlighting.  Perhaps now I have no excuse to play with this language.

    ActionScript

    ActionScript

  • Improved performance of auto-completion list cell renderer for huge completion lists.  Helps with languages with huge amounts of functions, such as PHP.
  • When using SearchEngine, if the next match isn’t currently visible, center the found/replaced text after the search operation.  This is a seemingly small change but is a nice usability improvement, and is seen in better editors like Eclipse.  For example, if your cursor is here:
    Starting to Search

    Starting to Search

    And you used SearchEngine#find() in RSTA 1.4.1 to find the next instance of “clip”, the next instance would be selected and brought into the visible area like so:

    SearchEngine#find() result before 1.4.2

    SearchEngine#find() result before 1.4.2

    Note that the next instance is selected, but is barely scrolled into the view.  Starting with 1.4.2, the next match is scrolled to the center of the text area, vertically:

    SearchEngine#find(), after 1.4.2

    SearchEngine#find(), after 1.4.2

    If the next instance of the text you’re searching for is already visible, the editor is not scrolled, the text is merely selected.  If the next match is not currently visible, however, that’s when it will be scrolled to the center of the view.

  • Fix for SourceForge bug 2998448: regex “replace all” is always case-sensitive.
  • SearchEngine’s concept of “whole word” is more accurate now (allows for punctuation, such as ‘,’, at the end of words, for example).  Previously, a “whole word” had to be completely surrounded by whitespace.
  • Added start of JUnit tests for SearchEngine.java.
  • SearchEngine bug fixes for replaceAll() with regex and match case/whole word enabled.
  • Fixed auto-complete bug with overloaded functions.
  • Fixed auto-complete bug – capitalization should be corrected when completing a parameterized completion.
  • Improved properties file syntax highlighting: ‘:’ can divide name/value pairs.
  • Added “our” keyword to Perl syntax highlighting.

Grab it on the SourceForge page today!