Sunday, August 26, 2007

Ruby Screnshot of the Weeek #17: Spelll Checkinng

WARNING: This blog entry was imported from my old blog on (which used different blogging software), so formatting and links may not be correct.

One of my favorite plugins for NetBeans 5.5 was Jan Lahoda's spell checker.
It turns out Jan has updated it to work with NetBeans 6.0, so I wrote some bindings for it to work with Ruby as well.
Briefly, it highlights spelling errors in comments and documentation (=begin/=end) sections. This also works in
embedded Ruby code in RHTML files, and in RHTML files it also spell checks the text content. Ok, screenshots:

The above is the documentation for Rails' url_for method. As you can see there are a couple of typos.
If you place the caret on one of the words a lightbulb will appear in the left side gutter; press Alt-Enter
to see the possible fixes:

As you can see, you can very easily add known words that aren't in the default dictionary to your own private list.

Here's an RHTML/ERB file:

Since this is a file in one of my own projects, NetBeans offers to add this word to a project-specific dictionary. This wasn't available for the above Rails source file since it's in a library outside of my projects.

The Ruby spell checker currently skips words in comments that look like Ruby identifiers, such as
CamelCase words, method_name words, and :symbols. Single-character words are also skipped. Finally, it skips
rdoc preformatted text (indented comment content) since that typically contains code fragments which contain
lots of unrecognized words. It might be an interesting improvement to try to help with typos in actual
class and method names, such as a "Controler", but I've gotta figure out a way to avoid generating tons of false positives here (what's a Scanf? :-)

I've uploaded a version which should work with NetBeans 6.0 here. Unzip it, then go to the Tools | Plugin Manager, open the "Downloaded" tab and install the individual nbm files. (You may have to restart the IDE.) The zip includes an English dictionary. This is the dictionary from ispell (unzip the dictionary.nbm file and you'll see it). You can add other languages in the Options dialog; these should be ispell dictionaries. You can also change the text locale in the Options dialog; when I opened some files in the RSpec distribution it immediately complained about the British spelling "behaviour" instead of the American spelling, "behavior". I presume this would be fixed by switching from en_US to en_GB (both are included).

P.S. Somebody asked me for 6.0-compatible versions of the strip-whitespace and highlight-tabs modules; here

P.S.2. The spell checker modules obviously work for Java too; if you've been looking for NetBeans 6.0 spell checking, grab the same .zip but skip installing the ruby-bindings .nbm file.

No comments:

Post a Comment