Wednesday, September 26, 2007

Ruby Screenshot of the Week #19: Comment Reformatting

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


I've been working on beefing up the RHTML support this week, but since I'm not done yet I'll talk about that next week. Instead I'll show you a feature that's actually in beta1, but you may not be aware of.



Let's say you have this code:





Have you ever wondered what the vertical faint red line on the right hand side of the editor is? It's the soft text limit line. It's telling you that beyond this line, you're going over 80 characters. There's nothing magical about 80 - you can configure it to something else, as I have done here, but more on that later.



Anyway, this comment is obviously not pretty since I've pasted in some text with long lines. This happens to my comments all the time after I edit them, removing a sentence here or adding another there.
But let's get to the point. Place the caret somewhere in the comment (as I have done). Now press Ctrl-Shift-P (on OSX, Command-Shift-P). Voila - the paragraph gets reformatted:






Notice that the IDE understands RDoc conventions. It has left preformatted code alone, and has recognized the numbered list and has formatted it appropriately. (There's also a hidden mode you can enable such that it reflows the current paragraph automatically as you edit comments.)



You can configure the text limit line in the general editor options - it's called "right margin":






One other interesting thing you can do with comments is view how RDoc will format them. Just use the normal "show documentation" gesture (Ctrl-Shift-Space, or Command-Shift-Space, to show the documentation for the symbol under the caret). This normally shows the documentation for a class or method that your caret is pointing to, but inside a comment, this will show the comment itself rendered rdocily:






That can be handy to check your docs as you're editing them (although this wasn't working properly in beta1, so get a daily build). The above example doesn't contain a lot of interesting rdoc markup, but let's say you brought this up on for example the form_tag method, you'd see something like this:






Notice how some of the code fragments are syntax highlighted as well - this is taking advantage of the enhanced rdoc rendering I've described earlier. And when tweaking your documentation, don't forget spell checking!



Finally, the above comment screenshots are a bit boring. Inline use of rdoc tags are also syntax highlighted. We were just discussing the meanings of the various colors on
dev@ruby.netbeans.org, and the following screenshot shows the meanings of the various syntactic constructs. Notice how rdoc tokens like :nodoc: and words surrounded by underscores are highlighted:





Thursday, September 20, 2007

Ruby Screenshot of the Week #18: Errors and Snippets

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


Tim Bray just wrote about error messages and their occasional difficulty for users. I ran into the same issue myself a couple of weeks ago when somebody filed a bug that NetBeans didn't correctly handle Ruby documentation markers. When looking at the user's source, I realized the error was right in the user's source file - but the parser message hadn't been particularly helpful: Syntax error, unexpected =.



This of course seems like an area where the IDE can help. So, as of the latest builds, there are some error rule handlers (in the experimental hints plugin) to help with this. Suppose you try to add in a documentation block like this:






The lightbulb on top of the stop sign tells you there's an associated suggestion. Press Alt-Enter to see the error message and suggested fix:






Applying the fix will obviously correct the indentation of =begin and =end. Here's another example - opening a file with ambiguous parameters:






I would really like your ideas on other common error patterns I can detect and better yet, fix. (See
RubyFeedback or leave comments here.)



While we're on the topic of quick fixes, the experimental hints also include some new suggestions for converting between brace blocks and do/end blocks. If you place the caret within the first line of a do-block or a {}-block, a little lightbulb will appear in the left margin. If you press Alt-Enter, you'll see some applicable fixes:






The exact list of choices shown obviously depends on the block. If you do this from a do/end block, the conversion goes in the opposite direction. And if you're looking at a multi-line block rather than a single line block, it will offer to collapse the block into a single line rather than expanding it as shown here. (It only offers this if it can fit the statements on a single line within the right-hand side margin, as shown by the faint red line in the editor.)



Unsurprisingly, applying the first fix gives us this source code for the block:






(This operation will sometimes also insert parentheses around the previous argument list when necessary, since {}-blocks have different precedence than do-end blocks.)



Finally, I just fixed some bugs in the code template handling code. If you invoke code completion you should now see the possible code snippets that match your input - along with their tab trigger names on the right and the full code template in the documentation popup:






That's it for now. Don't forget that NetBeans 6.0 Beta 1 was just released. The
New And Noteworthy document has the rundown on the new features included since Milestone 10. (Most of the things I've described in this blog entry were checked in after the beta cut off but beta is more stable for regular use.)



P.S. Rails creator David Heinemeier Hansson had some nice things to say about Sun's Ruby and Rails efforts. There's no evil plan, I promise!


Friday, September 7, 2007

Hello World!

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


The "Java Posse Hello World Tour 2007" is about to kick off :-) Carl, Dick and I are heading to Norway next week for JavaZone, where we'll do a live session as well as hopefully get some great interviews and just have fun. I'm also doing a talk on Ruby Tooling.



Joe can't make it - he works on the web store at Apple, and apparently they're busy selling stuff! We're also going to JavaPolis in Belgium in December. I'm not sure if I'll be able to go yet, but the other three guys are confirmed.



If any of you will be at JavaZone next week, please say hi!



Here's our world tour poster, courtesy of Oliver Widder:






New Demo Screencasts Available

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



NetBeans.tv was recently launched. It's a community site where you can view, upload and rate videos related to NetBeans, such as demos and tutorials, interviews, and so on.



Cindy Church has recorded and edited together three demos where I show NetBeans and the Ruby support.






  1. The JavaOne Demo (9 minutes). This is roughly the same outline I followed for the demo in James Gosling's keynote at JavaOne this year. It's a demo which shows both Java and Ruby editing capabilities as I create some JPA entity classes in Java, and then proceed to access these from a Rails application using JRuby.

    • You can download a higher resolution version of the video here (120Mb).
    • The demo script is available here.



  2. Code completion (2 minutes). In this brief demo I show some simple code completion scenarios for Ruby. You can also download a higher resolution version (27 Mb) of the video. I was winging this demo (without a script) so I didn't spend much time on the various types of code completion, but take a look at this blog entry where I get into a bit more detail. Also note that the code completion documentation has some additional smarts to it above what rdoc gives you, described here.






  3. Quick Fixes
    (3½ minutes). In this demo I show some of the quick fixes available for Ruby. Some additional hints were added after the demos were recorded - take a look at
    this wiki page for an up to date list.
    You can also download a higher resolution version (44 Mb) of the video.



Seeing myself on the video screen makes me super happy that Java Posse is an audio-only podcast!



A big thanks to Cindy Church and Mike Quillman who did all the hard work on these demos.