Timesavers: CFEclipse Snippets

Wednesday, April 29, 2009

This is part of an ongoing series on Timesavers. The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

Of all CFEclipse's features, none save me as much time as "Snippets". Eclipse has a built-in snippets feature, but for my part, I think CFEclipse's implementation is superior.

You create snippets in the Snip Tree view. You give it a name, a "start block", and optional "end block", and a "trigger". In addition, you can use "variables" to have the snippet inserter prompt you for stuff. More on that later.

First, here's what the dialog looks like for creating/editing a snippet:

snippet_new

Trigger Text


For me, its killer timesaver is trigger text. I don’t have to open up the snip tree view, navigate through a tree of snippets, and click to insert. Just type the trigger text and hit Ctrl-J.

For example, I have a snippet for creating a new CFFUNCTION. In a cfc, I simply type: function and then hit Ctrl-J. Here's what my snippet looks like:

snippets_function

And here's the popup I get when I hit Ctrl-J

snippets_functionpopup

I assign triggers to all the snippets I use on a day to day basis. I do have a number of snippets I use rarely, but I keep them as snippets because I figure if I have to type it more than once, it’s worth being in a snippet. But since I rarely use them, I’d forget the snippet trigger anyway.

If you were to chop out the trigger functionality tomorrow, I could measure my productivity loss in hours over the course of a year. And I’m not a fan of losing hours.

Variables

Variables are placeholders for text that you will be prompted to enter when you insert a snippet. For example, in that function snippet above, you saw this:

cffunction name="$${Function Name}" output="false" access="$${Access:public|private|package|remote}" returntype="$${Return Type:any|void|string|numeric|struct|array|query}" hint="$${Hint}"

And then when I inserted the snippet, it gave me a dialog where I'd populate those placeholders. If you don't enter anything, it just enters an empty string instead. Note also that you can create a dropdown list by using a pipe-delimited list, as in the "returntype" attribute above. Finally, if you use the same variable twice in a snippet, it will only prompt you for it once and then it will insert it in each place it was requested.

CFEclipse comes with several useful built-in variables you can use, too. They can be found at the official documentation site: http://trac.cfeclipse.org/cfeclipse/wiki/CFSnippets

You can watch Mark Drew’s video on using snippets here: http://cfeclipse.org/assets/movies/07_Snippetsfla.html

Finally, if you’re interested, here are some of the snippets I use every day. Many of these were created by my former colleague and all around good egg, Mike Rankin.

Bottom line: Next time you find yourself typing code that you've typed more than once, stop. Add it as a snippet, assign it trigger text, and execute the snippet by typing your trigger text then hitting Ctrl-J

Timesavers: CFEclipse Scribble Pad

Monday, April 27, 2009

This is part of an ongoing series on Timesavers. The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

One of my favorite CFEclipse features is the "Scribble Pad". Its primary purpose is exactly what its name suggests: to jam out some quick, throwaway code. I use it all the time when I come across a new function I want to test, or I want to see how a chunk of code will behave in isolation before I drop it into real production code.

The scribble pad is simply a .cfm file that you keep in a project somewhere. I'm a big fan of having at least one "Sandbox" project in my workspace, so that's where I keep my scribble pad file. Here's how I set up scribble pad:

  1. Ctrl-N and create new CFML project named "Sandbox"
  2. Store project at c:\inetpub\wwwroot\sandbox
  3. Ctrl-N to create new file named "scribble.cfm" in that project
  4. Hit the scribble icon in the toolbar (it's the one that looks like a pencil).
  5. The first time you do this, it should prompt you for the location of your scribble file. Point to your scribble.cfm, and give it the appropriate URL. In my case, it's http://localhost/sandbox/scribble.cfm

Then, when you have some code you want to try out, hit F8 or click the scribble icon. This will load your scribble file. It will also load the CFEclipse Browser View and run the scribble.cfm page. As you modify your code, hit F5 to refresh the Browser view and see your changes. You do not need to give the browser focus in order for F5 to refresh it; you can keep your cursor in the code.

Here’s what it looks like:

scribble_load

Then, as you monkey with the code, you simply hit refresh in the Browser view to see the changes.

Note: if you hit the scribble icon and nothing happens, you may need to set up the scribble in your preferences.

Window -- Preferences -- filter on Scribble

It'll pop up a box that looks like this:

scribbleprefs

Then, enter in the appropriate information. In my case, I entered "scribble.cfm" as the file, "sandbox" as the project, and http://localhost/sandbox/scribble.cfm as the URL. If you don't enter in the URL, then the browser view will NOT load with the scribble URL; rather, it'll load empty, and this isn't what you want.

For me, scribble is a huge timesaver because it gives me a quick place to test stuff without having to a) run the code inside my app or b) create new files for running it in isolation.

Bottom line: Scribble pad rocks. F8 loads it.

Timesavers: Eclipse Quick Diff

Friday, April 24, 2009

This is part of an ongoing series on Timesavers. The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

Have you ever been editing your code, and sometime down the road -- maybe 5 minutes, maybe 2 hours, maybe after lunch -- you break something. It used to work, and now it doesn't. You're thinking, "what change, of all the beautiful edits I've made, broke my fortress of code?" Being an experienced Eclipse user, you smile and say to yourself, "I know, I'll compare to my local history!". Or maybe you decide to simply compare to the latest SVN Version.

So off you go, right-clicking on the file, selecting "compare", and then choosing a comparison target. Often, this is a perfectly reasonable decision. Well done, good sir.

There is, however, a quicker way to easily see the changes you've made to your code in an editing session, or even across sessions: Quick Diff

On the left side of your Eclipse editor is the "ruler" bar. It's the thing with the line numbers. And if you have Quick Diff enabled, it's also the thing with the pretty colors showing you what lines have been added, changed, and deleted. Here's what Quick Diff looks like when I change a line of code and then hover over the ruler bar color decorator:

quickdiffpopup_1

Notice there's an "F2 for focus" line at the bottom of the popup. Here's what it looks like when you do that:

quickdiff_highlighting

What's cool is that you can select this text from the popup. So if you see something in your Quick Diff that you think "OOOH! That's the code I monkeyed with. Let me grab that and drop it back in and see if that fixes my problem", you can simply copy it from the popup and off you go.

"Added" lines of code will merely result in a "+" for each added line in the popup; Changes will show the full lines that were changed (though they won't give you the nifty "Compare Editor", which is one of the compelling reasons for using the full-on "Compare With" stuff). Deleted lines will give you a small line in the ruler bar. For example, I deleted a function, hovered over the black line, and this is what I got:

quickdiff_deleted

To enable Quick Diff, simply open the Eclipse preferences (ctrl-shift-L, ctrl-shift-L), filter on "Quick", select the "Quick Diff" label, and have at it. Here you can also choose the Reference Source and change colors. It looks like this:

quickdiff_preferences

I use "Pristine SVN Copy" as the source for projects connected to SVN, and "Version on Disk" for non-SVN projects.

Bottom line: Enable Quick Diff, then hover in the gutter for popups showing you what’s changed. F2 to focus so you can select code

Timesavers: Tabaholic

Wednesday, April 22, 2009

This is part of an ongoing series on Timesavers. The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

Eclipse Resource Navigation

If you're like me, you probably have a lot of files open in Eclipse at any one time. You probably have done the following things at some time in your career:

  • Moused over to an already open file whose tab is visible in your window
  • Clicked on the little double arrow and drilled down to an already open file that wasn't visible in your window
  • edited a file, saved it, opened another file to check something out, then wanted to go back to the place where you were last editing

This TimeSaver is dedicated to showing how Eclipse makes these operations a snap. Of course, we're talking about the keyboard. As you work with Eclipse, you'll learn that its developers are highly fond of keyboard shortcuts. Hit CTRL-Shift-L to see the current active shortcuts, also known as "Bindings".

Getting to open files quickly

First, put down the mouse. It's sucking time away from you and your precious code! Every time you find yourself grabbing the mouse to go to an already opened file, stop. Pinch yourself. Yank on the cilice. Whatever. But put the damn thing down. And hit: Ctrl-E Go ahead, try it right now. We'll still be here. Go to Eclipse, open up a few files, and then hit Ctrl-E. Pretty, isn't it? Notice how, like so many popups in Eclipse, it has a little area at the top where you can type? It's a filter. You can use wildcards, too. My favorite way to use it is when I know what file I'm looking for, let's call it "SomeTest.cfc", I hit Ctrl-E, type "So" and it'll filter down to the file I'm looking for. Hit Enter, and bam, you're at the file.

Back from whence you came

In that third scenario up above, you edited a file, went somewhere else, and then wanted to go back where you were. Eclipse has a shortcut for that: Ctrl-Q. Go ahead, try it.

Did it work? If you were editing a CFM or CFC file in CFEclipse, it probably didn't. That's OK. We're going to take care of that. CFEclipse overrides the Ctrl-Q binding with the "repeat last tag" action. I personally don't use that, so I want to get rid of it. Let's open up the Keys preference page. The sloooooow way: Window -- preferences -- filter on keys The fast way: Ctrl-Shift-L, Ctrl-Shift-L again. Go ahead, try it. It's going to pop up a window that looks like this. Now, in the filter box, type Ctrl+Q. Note the "+". You should see two entries. Simply remove the binding for "Repeat last tag" by selecting it and then clicking the "Unbind Command" button, or if you like that, you can assign it to another keyboard shortcut. Now, edit some text, move to another file, then hit Ctrl-Q. Bam... back where you were. Nice, eh?

I need to get to line 500... of line 2529

You know you've written some really long files in your day. Admit it. Sometimes, you actually have to maintain those works of modern art, and it's nice to be able to get quickly to where you need to go within that file. Usually this comes from a bug report with a tag context / stack trace attached to it. Simply hit Ctrl-L, then type in the line.

Tab-to-Tab

Ever wanted to just toggle through your open tabs? Simple: Ctrl-PgUp to go leftward through your tabs, and Ctrl-PgDown to go rightwards

The Back Button, Eclipse Style

I'll admit, this isn't one I use much, but maybe you'll get some mileage out of it. It's like your browser's Back button, but for Eclipse: Alt-Left Go ahead, try it. Guess how you go "forward".... yup. Alt-Right

 Summary:

Ctrl-E to navigate open files Ctrl-Q to go back to your last edit location Ctrl-L to go to a specific line Ctrl-PgUp and Ctrl-PgDown to toggle through your tabs Alt-Left and Alt-Right to go back and forth

Driven By The Cold - TDD, MXUnit, and ColdFusion (Part 1)

Tuesday, April 21, 2009

It was a great learning experience to work with such talented people to deliver this collaborative writing project - peer/technical reviews, editing, editing, and more editing. This made blogging look like post-it hacks! A big thanks to Adobe for providing the venue, support, and process to publish technical know-how and best practices. Building good tools is one thing; showing people how best to use them is another. It's becoming glaringly apparent to this developer that a software product's strength lies equally in its ability to educate as well as it's ability to solve real-world problems. Community involvement is critical, and organizations that foster this collaboration will have a positive impact on the community. Part 1 is available now with Part 2 coming very soon. http://www.adobe.com/devnet/coldfusion/articles/testdriven_coldfusion_pt1.html Test and be Happy! the guys at mxunit.org

Timesavers: Ctrl-Shift-R

Monday, April 20, 2009

This is part of an ongoing series on Timesavers . The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

What you think of as files, Eclipse thinks of as resources . Resources represent a file in the Navigator or Package Explorer view; they represent a file opened in an editor. Your workspace comprises all the resources in your workspace (and a whole lot more).

This TimeSaver is dedicated to finding resources in your workspace .

How To Quickly Find Resources

By now, you should know I'm a fan of the keyboard. Navigating through trees of files is dog slow. I don't mean 8-week-old-yappy-rat-terrier-puppy slow. I mean 25-year-old-coon-hound-eyes-are-crusted-over slow. Fortunately, Eclipse gives us the "Resource" finder. Lucky people learn about this beauty early on in their Eclipse usage; others go without for a long time, to their woe. They Twitter, "How did I not know about Ctrl-Shift-R?" or "w00t! Ctrl-Shift-R!" or "OH: the dumbass in the cube beside me just found Ctrl-Shift-R. Dumbass. Wonder when he'll learn to breath out his nose".

Why is this? I think it's because of the "resource" vs. "file" nomenclature discussed above. Why, for example, would you think to: Navigator --> Open Resource and expect that to pop up the single greatest popup in the history of bits and bytes? You wouldn't. That's why it goes undiscovered for so long.

Notice the keyboard shortcut for "Open Resource": Ctrl-Shift-R . Burn that into your brain. Ctrl-Shift-R. Ctrl-Shift-R. Ctrl-Shift-R. Stop drinking. Stop eating. Stop smoking stogies. Stop raising your children. Stop everything until you have absorbed Ctrl-Shift-R. It is the fastest way to get to files. It looks like this, and it is my friend:

Notice how it filters when you type stuff? Notice I used a * to do a wildcard filter? Also, notice that little black triangle on the right hand side? You can drop that down and filter your search on Working sets for added radness.

Another neat feature: it lets you select multiple files and open them. Need to super fast find all your TestCases and open them (why? I dunno)? Ctrl-Shift-R, then *Test.cfc. Tab into the "Matching Items Window, hit Ctrl-A, then Enter. Bam... you've got more open files than you know what to do with.

Next time you find yourself grabbing the mouse and navigating through your tree of files, Stop. Put the mouse down. Even if you've found it already. Put the mouse down, hit Ctrl-Shift-R, and start typing.

Timesavers: Common Eclipse Shortcuts

Friday, April 17, 2009

This is part of an ongoing series on Timesavers . The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive
This TimeSaver is dedicated to common keyboard shortcuts that everyone should know. Well, let me back off of that. If you like being slower than a 3-toed Sloth, that's your prerogative. If you want to be fast, put the mouse down and use these shortcuts.
  • Ctrl-S to Save
  • Ctrl-Shift-S to Save All
  • Ctrl-W to close the current document
  • Ctrl-Shift-W to close all current documents
  • Ctrl-N to pop up the "New..." dialog. Please, when you're creating new files, don't use the mouse. In your navigator or package explorer, put your mouse where you want your new file, and hit "Ctrl-N", then filter on the type of file or project or whatever you want to create, and hit Enter.
  • Ctrl-M to maximize (and minimize) the current active window. This works for editors and views.
  • Ctrl-F to find stuff within your active editor
  • Ctrl-K and Ctrl-Shift-K to do "find next". I love these things! You highlight a word in your file, then hit ctrl-k to find other instances of it, one at a time. Go ahead, try it. use Ctrl-Shift-K to find backwards
  • Ctrl-H to find stuff in other files in your workspace.
  • Ctrl-Space to pop up content assist (aka tag/function insight). This one bears some elaboration for us CFMLers. You know how when you type a function name, say reFind(, and it pops up the content assist? but then when it disappears you don't know how to get it back up again? Just hit Ctrl-Space. Go ahead, try it. Go find a function in your code, put your cursor after the paren, and hit Ctrl-Space. For the energetic, read my long diatribe with a mini-section on what I call "Ctrl-Space-Learn".
  • Alt-Up and Alt-Down to move a whole "selection" (a line, or a chunk of lines) up or down
  • Tab to indent, Shift-Tab to de-indent
  • Ctrl-Shift-L to pop up a box showing other keyboard shortcuts

How do you get the swing of these?

I started by keeping a printout on my desk. It was a start. But the real key for me was to try to develop a palpable aversion to the mouse. For example, if I found myself mousing to create a new file, even if I were almost finished. I'd cancel it and do it with the keyboard. I'd do the same thing for all the other operations above. I try to nurture good developer habits; becoming keyboard-addicted is one worth developing yourself.

Timesavers: Launchy

Wednesday, April 15, 2009

This is part of an ongoing series on Timesavers. The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

Launchy is in my top 5 favorite applications, ever. Simply put, it makes it braindead simple to "do stuff" with just the keyboard. Some of the things I use it for:

  • Running bat files
  • Opening applications (Eclipse, Fireworks, TweetDeck, etc)
  • Opening/executing RDP shortcuts
  • Quickly navigating to directories

To use launchy, you simply hit "alt space", and the launchy window pops up. You start typing, and it looks in its cache for stuff that matches what you're typing. When you find something, you hit "enter". Your "thing" launches. That's it.

Here's what it looks like:

Once installed, Launchy by default will scan everything in your "All Programs" in the Start Menu. However, it's highly configurable, and this is where it shines.

To register anything with Launchy:

  1. pop up Launchy with "alt space"
  2. click the "gear" icon in the top right
  3. click the "catalog" tab
  4. In the "Directories" box, you can use the "+" and "-" buttons to add directories. Once a directory is selected, you can add the File Types in that directory to add to the catalog. I commonly use .bat, .lnk (those are windows shortcuts), .rdp, and .exe
  5. Then you click "Rescan Catalog" and you're set! (you can set it to auto-scan the catalog every X minutes. Play around in the "General" tab to find out how)

Example

Remember the "Bat File Timesaver" post? At the end, I said that there was a better way to launch bat files. You can launch them with no mouse clicks at all by simply registering them with Launchy! For example, in the screenshot above, I started typing "ecl" to launch eclipse. But I don't launch eclipse with its executable; instead, I launch it with a bat file that contains certain settings:

runEclipse.bat

c:\eclipse_34_rcp\eclipse.exe -showlocation -vm "C:\Program Files\Java\jdk1.6.0_12\bin\javaw.exe" -vmargs -Xmx512M -XX:MaxPermSize=256m -XX:+AggressiveOpts -XX:+UseParallelOldGC -XX:ParallelGCThreads=2 -XX:ThreadPriorityPolicy=1 -Xverify:none

This file lives with all my other bat files in a directory somewhere on my file system. So to register this and the others with Launchy, I just add that bat file directory in the "Catalog" tab, add the .bat file type, and hit Rescan. Done! Now, when I want to launchy eclipse, I simply hit "alt space" and start typing "eclipse" and up it will pop.

Here's what the config looks like:

Easy access to directories

If you find yourself accessing certain directories over and over again, you may have created a shortcut to that directory. Then you point and double-click to open it. You can shorten this even further by adding directories into Launchy. For example, I poke around in the mxunit and mxunit-cfmeetups directories all the time. Rather than point and click to them, I use launchy. For example, if I want to get into the "plugindemotests" directory inside of mxunit, I hit "alt space" to pop up Launchy, then start typing "plu" and it'll autofill that directory. I hit enter, and it opens in Windows Explorer. So far, I've added a lot of common directories and I've seen no slowdown in launchy's ability to find just what I'm looking for.

To configure launchy for directories, just add a directory into the "Directories" box, and on the left hand side, don't add any file types. Instead, check the "Include Directories" checkbox.

Here's what launchy looks like after adding a Directory:

Alt Space, baby!

Timesavers: Batch Files

Monday, April 13, 2009

This is part of an ongoing series on Timesavers. The goal is simple: short, easily-digestible posts designed to help developers get faster and more productive

A batch file on Windows is a .bat file that contains one or more commands. You can execute .bat files by double-clicking, via the command prompt, or even as an "executable" in a scheduled task. Their power as a timesaver is in their ability to encapsulate common functionality so that you don't have to click a lot or remember a lot. This is predicated on the idea that every mouse movement/click is itself a time waster.

Common Example How do you start/stop/cycle ColdFusion? Certainly one way to do it is through the Windows Services panel. Let's count the mouse movements:

  1. Start Menu
  2. Control Panel
  3. Administrative Tools
  4. Services
  5. Scroll to Macromedia JRun CFusion Server
  6. Click the "Stop" or "Start" button up top

And that's just for one action. Multiply that by the other services you frequently cycle. SQLServer? MySQL?

Bat Files for Scenario Above

CF_Stop.bat

NET STOP "Macromedia JRun CFusion Server" NET STOP "Macromedia JRun Admin Server"

CF_Start.bat

NET START "Macromedia JRun CFusion Server" NET START "Macromedia JRun Admin Server"

CF_Cycle.bat

NET STOP "Macromedia JRun Admin Server"

NET STOP "Macromedia JRun CFusion Server"

NET START "Macromedia JRun Admin Server" NET START "Macromedia JRun CFusion Server"

Where to store them? Obviously, you don't want to go putting dozens of bat files on your desktop. So where to put them? I keep mine in a directory, and then add a shortcut to that directory into my windows taskbar by following these steps:

  1. Right click in taskbar
  2. select "Toolbars"
  3. select "New Toolbar"
  4. Navigate to the directory where your bat files live. Click "OK" through to the end.

From there, you can access your bat files from that new toolbar right from your windows taskbar. The nice thing about this approach is that you don't need to double-click on the file... just single click. Here's a screenshot of what it might look like:

Isn't there a better way?

Yup.... Stay tuned for the next Timesaver!

New MXUnit released: The Community Edition

Wednesday, April 1, 2009

We're pleased to announce a new release of MXUnit. This one's especially meaningful to us because it's largely contributions from the community. Big props to: Barney Boisvert for contributing "run this method" links to the standard HTML test output. This has been in the EXT Grid view since its inception, but that feature never made its way back into the original runner. This is a particularly welcome addition because the standard test runner is much faster than the EXT view. Jamie Krug contributed a patch and tests for deficiencies in makePublic(). Our exchange is here. I gotta tell you, I wish open source worked like this all the time. Jamie posted a bug to the bug tracker -- a very well written bug, by the way -- included patches, went back and forth with me, wrote tests. Outstanding. Denny Valliant has been bugging us forever about making debug() available to all components, not just your tests. He got sick of waiting on me, so he did it himself. Thus, request.debug() was born. It rocks! This is one of those things that will cause some folk to throw up their hands and say "but you're violating [insert whatever it is we're violating] here". I agree. We are. Don't use it if it offends you. Adam Haskell contributed the first of several planned function attributes: mxunit:ExpectedException. Bill, Adam, and I have been going on about this for a very long time (too long!) in preparation for MXUnit 2.0. Blah blah blah. Meanwhile, while we were yapping, Adam wrote the expectedException functionality (and Tests). It's such a time saver! In addition, you'll notice that the links above all point to the new MXUnit wiki. Thank Adam for all of that! We still have a lot of content to move over from the existing MXUnit docs. It'll get there (some day). We've also had a lot of great feedback and ideas contributed from community members. Thanks to Bim Paras, Tim Farrar, Bill Rawlinson, Bob Silverberg, and all the other smart people for the excellent dialogue! Finally, the eclipse snippets have been updated to reflect the expectedException attribute over the old try/fail/catch method for testing expected exceptions. If you like to code fast, please open up the instructions in the mxunit/cfeclipse/snippets directory. You'll be glad you did. Thanks everyone!