SlickEdit carries out many of its commands through its slick-C programming language (note that both Brief and Emacs have their own languages as well). SlickEdit lets you write your own macros, or do a simple record / playback. This comes in handy when the syntax for find and replace gets too dicey.
As an example, instead of the find and replace above, you could write a macro that searches for strcat, places the cursor at the end of the string, and then pauses. Next you could copy the string to the clipboard or do some other editing you have planned. Continue the macro and have it paste the result of your copy, skip to the end of the line, and add a comment that the line changed.
As another example, you might write a macro that skips to the beginning of your current function, copies the name to the clipboard, inserts a standard comment header in front of it, and then pastes the name of the function. The possibilities are endless.
|Figure 6. Refactoring: SlickEdit's Quick Refactoring feature provides several options based on the code you select for refactoring.|
Often, you'll find yourself in a situation where the code you have is fine—the only problem is that when you first wrote it, you didn't know how often you were going to repeat a sequence of operations with a common set of arguments. Now your code's all cluttered up with repeated function calls. It's time to refactor (see Figure 6).
Here's where you can take advantage of SlickEdit's convenient refactoring feature, which lets you select some lines of code and create a function out of them. When you choose this option, SlickEdit presents you with some choices (see Figure 7). Based on your selections, it can take the code you've selected, move that into a new function, define any variables you were using at the beginning of the function, and create parameters that allow the values to be changed by the caller. Oh, and it can also replace that spot in the code where you selected those lines with a call to the new function!
|Figure 8. Refactoring Prompt: Before making any changes, SlickEdit gives you a chance to see exactly how the change will affect your code and accept or refuse the change.|
This feature is very nice—but watch the results carefully—because you may find instances where SlickEdit uses C++ references in places where a variable's value really doesn't need to be updated, or is already a pointer in the calling code.
Again, before it makes any changes, SlickEdit shows you exactly what it's about to do to your code (see Figure 8) using its "diff" feature, discussed next.
The diff program in SlickEdit is so powerful that's it's affectionately named "Diffzilla." Diffzilla is a combination compare/merge tool that can help you resolve differences once you spot them. You can also point tools like Perforce at SlickEdit and tell it to use that as the merge or diff tool rather than its internal version.
|Author's Note: I highly recommend this if you are using Perforce's merge tool. Diffzilla will attack files or even entire source trees, which is great if you are doing merges outside the control of your version control system, or across different instances of it.|
|Figure 9. Diffzilla Options: On the Files tab, you can browse to files with Windows Explorer or click the "B" button to operate on open files.|
In Figure 8, notice that Diffzilla shows the original version on the left, and the updated version on the right. As you highlight the different changes (using the "Next Diff" button), you have options to change the line or the whole block, in either direction. Figure 9 shows the Diffzilla dialog on the Files tab.
You can choose files using Windows Explorer by clicking on the ellipsis (…) button, or clicking the "B" button, which stands for "open buffers"—the files currently open in the editor. Diffzilla makes it easy to see differences or merge code in a readable way.
|Author's Note: A new feature called "Source Diff" takes this concept a step further and attempts to refine the differences it highlights to those that would alter program execution. This feature ignores white space changes, for example. Personally, I like to see white space changes, as we have strict policies on how white space is used where I work.|