Everybody Likes Shortcuts! Part 1, Navigation
January 20, 2015 Susan Gantner
I’ve seen a particularly sharp increase in the use of RDi (or Rational Developer for i) by RPGers this year. I suspect that has a lot to do with the fact that it contains the only editor that supports the new V7 all-free-format version of the RPG language. Even among shops that are not planning to make use of free form D specs right away, this limitation seems to have made people realize that the writing was on the wall and that SEU’s day had come and gone. One way that I gauge the interest in RDi is in the amount of requests for my RSE Quick Start Guide and Favorite Keyboard Shortcuts. The latest version of the shortcuts card was reprinted a few months ago and nearly half of them have already been given out. The last time we printed the same number of cards, it took around two years to get through them. It seems that people really like shortcuts, especially when it comes to RDi. So I thought I’d write a couple of tips about some shortcuts that may not be that widely known. This tip will concentrate on shortcuts to help you navigate your way through a source mem-ber. One of the big advantages of using RDi is that all the code is local on your workstation, which can make it faster and easier to find your way around, particularly with large source members. First, let’s look at the Ctrl+Home and Ctrl+End keys. These simply jump to the top (Home) or to the end (End) of the source. Both of these shortcuts work in many Win-dows applications, not just RDi. However, RDi adds a nice touch in that it automatically creates a “quick mark” at the line of code where you were when you hit the shortcut key. A quick mark is like a temporary bookmark that you can subsequently jump back to by using the Alt+Q shortcut. So imagine that you’re editing some old RPG code that uses a number of <shudder> compile-time arrays. One of the reasons I dislike compile-time arrays so much is that the definition of the array is near the top of the source and the data is at the opposite end of the source. In RDi, if I’m positioned on either the definition of the array or on a reference to an element of the array, I can use Ctrl-End to jump to the end of the member to look at the data. Then I use Alt+Q to get immediately back to wherever I was. Of course there are other occasions when jumping to the top or bottom of a member is handy, such as peeking at the standard comment block near the top of a member that many shops include or moving to the F-specs to make changes there. There’s another use of automatic quick marks that I use even more often. When I’m positioned on the name of a subroutine or an internal subprocedure in some RPG logic, I can use the F3 key to jump directly to the subroutine or subprocedure code. After I’ve studied the logic there–you guessed it–Alt+Q will take me right back to the EXSR or whatever statement I was on when I originally pressed F3. That’s because F3 is another shortcut where RDi sets an automatic quick mark for me. One of the most common questions I get about this particular shortcut when I’ve shown it to people is “why F3?” And the answer is: I have no idea. It does seem a rather odd shortcut to use for that purpose. I think most of us think “exit” when we think of F3. But it is a very handy shortcut, so give it a try. Even if you must first overcome the fear that it may close your source member! As I’ve noted, the Ctrl+Home, Ctrl+End, and F3 keys all automatically set a quick mark for you. It’s also sometimes handy to know how to set a quick mark manually anywhere you want. To do this, simply use Ctrl+Q to set the mark, and as with the shortcuts be-fore, use Alt-Q to get back that spot quickly. Note that Alt+Q also sets an automatic quick mark at the location where you were. So that means you can use Alt+Q to continually jump back and forth between two different parts of the code as often as you need to. There is only ever one quick mark available at a time and it is meant for short-term use. If you want to have a way to have multiple spots in the code that you can return to any time, even days later, then you probably want to look into using either Tasks or Bookmarks. These are very similar to quick marks except they can have names or descriptions and you can have as many as you want. They are also retained until you delete them so they can be very useful to mark important parts of the code for longer term purposes than quick marks. Paul Tuohy wrote a tip on using Tasks and Bookmarks so I’ll leave you to study that topic on your own here. While on the subject of source navigation, I’d be remiss if I didn’t give a shout out to one of my favorite RSE features: the Outline view. This feature allows me to quickly find where fields, data structures, subroutines, and subprocedures are defined and/or referenced in the source member I’m editing. Outline view has been my primary navigational tool for years, so much so that I’ve often commented that I don’t think I could write an RPG program without an Outline. Another tool that I’ve used to help with navigation is filtering. While the Outline gives me a list of every statement where a field is referenced and I can click on each reference to position to them one at a time, I sometimes find it faster to simply filter out all the code except those lines that reference that field. Then I can hone in on the statement that I’m interested in and then view it in context with the rest of the code around it. There are two ways to filter on a field name (or any other text for that matter, but field or structure names are the ones I use most often). The first is to find the field name somewhere in the source, select it (double click), then right click and choose Select-ed→Filter selection. You will then see only the statements with that field name. Position to the statement you’re interested in and then choose Show All from the context menu or use the shortcut Ctrl+W. If you just want to peek at the code around it, you can click on the + signs that appear to the left of each line. The second way to filter on a name is to use the Find/Replace dialog, which is the shortcut to this is Ctrl+F. Then key the name into the Find box and click the All button to the right. Alternatively, of course, you could also use the Find/Replace dialog to simply position to each use of that field with the Next button or the corresponding Shift+F4 shortcut. Sometimes you may want to filter the code by change date rather than on a name. This can be particularly helpful if you suspect a recent change to the code may be causing the bug you were just assigned to fix. This is easily done by bringing up the context menu anywhere in the editor and choosing Filter view→Date. The resulting dialog allows you to enter a single date or a date range to search for. If you prefer to navigate to each line changed within a date timeframe one statement at a time, use Ctrl+Shift+D (search by change date). In addition to finding bugs recently introduced into the code, I’ve worked with shops who find this helpful when doing code reviews. Wow! Until I wrote this tip, even I didn’t realize how many different ways I use RSE fea-tures to navigate through code. I’m sure there are more navigation tricks that I haven’t remembered to include here, probably even some that I haven’t found yet. If I’ve missed out one of your favorites, let me know! Susan Gantner is half of Partner400, a consulting company focused on education on modern programming and database techniques and tools on the IBM i platform. She is also a founding partner in System i Developer, a consortium of System i educators and hosts of the RPG & DB2 Summit conferences. Susan was a programmer for corporations in Atlanta, Georgia, before joining IBM. During her IBM career, she worked in both the Rochester and Toronto labs, providing technical support and education for application developers. Susan left IBM in 1999 to devote more time to teaching and consult-ing. Together with Jon Paris, she now runs Partner400, and appears regularly at many technical conferences, including System i Developer’s RPG & DB2 Summit. Send your ques-tions or comments for Susan to Ted Holt via the IT Jungle Contact page. RELATED STORY
|