Operating systems, development tools, and professional services
for connected embedded systems

QNX Technical Articles

 

Using the Developers' Features of ped (the Photon Editor)

by Jerry Chappell

Besides providing basic wordprocessing facilities, the Photon Editor (ped) also offers a number of features that can help in software development. In this article, I'll outline those features and others (keyboard shortcuts, markers) that you can use to speed up your programming cycle.

Working with source files

The ped editor has a number of features associated with C and C++ source file programming. (Although ped currently supports only C/C++ source files, your suggestions for further source support are welcome!)

First, check under Preferences (in the Edit menu) for the following setting:

"When a source file is opened, also open the corresponding header file."

This option lets you tell ped to automatically open a header (.h) file with the same name as any C/C++ source file (.c/.cc/.cpp) that's already opened. So by opening program.c, the corresponding program.h file (assuming it exists), will appear in a second buffer.

To switch between the two files, use the Ctrl-> and Ctrl-< shortcut keys (or use the Buffer menu).

Now that you're viewing a source file (.c/.cc/.cpp), you'll see a combobox on the status bar (bottom of the ped window). When your cursor moves throughout your document, the Function name combobox will change to display the name of the function where your cursor is resting. As you move your cursor, and as you write new functions, this label will always change to reflect the current function.

While this is a useful indicator, the real advantage is to open the combobox where all your functions will be listed. Click on any function to move your cursor immediately to the top of that function. And to jump quickly from one function to the next, click the Fn icon next to the combobox (left-click or right-click) or jump using these shortcut keys:

Ctrl-{

move to previous function

Ctrl-}

move to next function

Check the Preferences dialog (under the Edit menu) for an option called "List function names alphabetically". If this option is selected, your function names will be automatically sorted by name within the combobox. If it's not selected, then the function names will appear in the same order as defined in your source file.

Even using the combobox for the benefit of determining what functions are defined in your current document is a useful feature in itself, especially if your application has many source files to keep straight!

You can even jump to a particular function from the command line. Use the syntax:

-c functionname

to jump to the given function at startup (assuming the function exists in the opened source file). For example, if you issue this command:

ped -c init source1.cpp &

then ped will:

open with two buffers (source1.cpp and source1.h)

show source1.cpp

move to the last function starting with init.

Keyboard shortcuts

Suppose you're working with a large file that contains a number of functions that are difficult to remember or that simply require a large number of parameters in order to call. If a function you want to call is in the same file that you're editing, the Ctrl-Shift-E and Ctrl-Shift-P commands may come in handy.

Ctrl-Shift-E (enter a function)

Highlight any function name and press Ctrl-Shift-E to immediately enter the function specified. Your cursor will automatically jump to the highlighted function (if it's in the same file).

Ctrl-Shift-P (copy parameters)

The alternative to jumping to a function is to copy its parameters directly into your code where you're calling the function. Simply type the name of the function (without any braces or spaces) and press Ctrl-Shift-P. This will automatically insert the braces and all parameter definitions for the function you've specified. At this point, it's easy to replace the parameters with the data you need to pass. For example, if you type:

MinMax

and press Ctrl-Shift-P, your screen will show:

MinMax(int lownumber, int highnumber, char *error_string)

F10 (match braces)

Let's say you're searching through someone else's code, and they have a very poorly formatted coding style (of course!). If you're having trouble matching up their braces { }, you can easily find a matching brace by pressing F10.

Position your cursor next to the known brace, press F10, and the cursor will be immediately moved to the matching brace. This works for a number of pairs of punctuation marks, including ( ), { }, " ", ' ', and [ ]. This is great for trying to find a missing bracket that even the compiler can't quite pinpoint for you.

Ctrl-Alt-H (help text search)

QNX has a good set of online documentation that you can search for any text string. To facilitate this searching:

Highlight a word or phrase in your document.

Press Ctrl-Alt-H.

The QNX Helpviewer is launched automatically, and the highlighted text becomes the search phrase within the help docs. Your ped session itself isn't affected. There's nothing better than being able to double-click on something like ApCreateModule, press Ctrl-Alt-H, and immediately see the docs for that function!

Ctrl-Up/Down Arrows

While working on a document, I also find it useful to move the display up or down without actually moving the cursor -- maybe I want to see what variables I have defined just off the top of the display.

To move your document up and down by one line, use Ctrl-Up (up arrow) and Ctrl-Down (down arrow). If the cursor ends up off the top or bottom of your display, just move the cursor with one of the arrow keys to jump back to your editing position.

Ctrl-Shift-I (indent)

One of the most common programming requirements is to indent a block of text. You can do this simply by highlighting a block of text and pressing the Ctrl-Shift-I (indent) hotkey. To shift the text to the right, the highlighted text will have a tab character inserted at the beginning of each line.

Similarly, press Ctrl-Shift-U to un-indent the highlighted text by removing a tab from the beginning of each line.

Ctrl-Shift-F (find)

To search for text within a document, you can highlight it, copy it to the clipboard, open the find dialog, and paste the text from the clipboard into it.

Or you can use the Ctrl-Shift-F hotkey to show the find dialog with the currently selected text string already inserted; no copying or pasting is required.

Ctrl-Shift-0 (file search)

This keystroke will take any highlighted filename and search for the file in your current directory. If the file exists (remember, it must be in the same directory as the file you're currently editing), then it will be opened in its own buffer, and the display will switch to that buffer. Your current buffer is unaffected by this operation; you can switch back to it anytime, using the Buffer menu.

Using markers

One function that I find extremely useful is markers. As you may have noticed, they have their own menu. Any ped document can have up to ten markers defined. The marker information is stored with the formatting block saved at the end of the file (see the Preferences menu option; choose the Style & Markers tab).

Markers are indicated with a number from 1-10 in the bar on the left-hand side of the ped window. These markers simply stay with the line they were placed upon; you can jump to any one of them quickly using a keyboard hotkey or from the Markers menu.

When working in your code, you may need to jump to some other part of the document to work on another part of the code or to check existing code. To easily jump back to your current position, press Ctrl-Shift-1 (for the first marker) or use the Markers menu. A "1" will appear next to your current cursor position.

Now move around your document as necessary. When you're ready to jump back to marker #1, press Ctrl-1. Your cursor will automatically return to the first marker position. If you use the Markers menu, you'll notice that only the markers that have been previously set are available as destinations.

You can also jump to markers between buffers. If, for example, you have markers 1 and 2 defined in the first buffer, and a marker 2 only in the second buffer, you can press Ctrl-1 from either document to immediately display the first buffer and to jump to marker 1 in that buffer. Additionally, you can press Ctrl-2 in the first buffer to jump to its marker 2; any subsequent presses of Ctrl-2 will toggle your display between the marker 2 of each buffer.

To clear all the markers in the currently displayed document, press Ctrl-Shift-Backspace

Conclusion

I believe the nicest feature of ped is the fact that it's graphical. IMHO, it's the nicest looking editor available for QNX. It may not have as much flexibility as some of the macro-based text editors, but its special features make it useful and convenient for everyday use.

I hope that these details of the behind-the-scenes features of ped will help you use it at least occasionally. Remember, ped is a relatively new program -- if it doesn't have all the features of your dream editor, please send me your suggestions!

Thank you for your interest.