TOC PREV NEXT INDEX DOC LIST MASTER INDEX



The Apex Text Editor

You can use any UNIX editor such as vi, or ed —— to edit text files in the Apex environment. However, you may prefer the Apex text editor because it is integrated into the rest of the Apex system and supports mouse-driven editing operations. Apex also provides a customized Emacs editor. The editing features of the Apex text editor work just like those used by the Apex language-specific editors, described in The Ada Editor and The C/C++ Editor. The Apex language-specific editor, in addition to its editing features, offers extra features for editing Ada and C/C++ source files.

About This Chapter

This chapter describes the commands available from the Apex editor's File, Edit, View, Navigate, and Compile menus. The Control menu is described in Using and Customizing Summit/CM. The Debug menu is described in Using the Apex Debugger.

The topics covered in this chapter are:


The Apex Editor Window

The text editor is used to create, view, and edit source code and other kinds of text files and is illustrated in Figure 13 .


Starting the Text Editor

There are several ways to start the text editor. For example, you can open:

Figure 13 The Apex Text Editor Window

Note: The text editor was designed using the standard Motif text widget, so its basic editing commands are similar to those of many other Motif clients (and emacs, too). Some keystroke combinations recognized by the editor are actually accelerators for commands on the Edit menu.


Using the Text Editor

Text editing commands can be executed by clicking the command in the Edit menu or by using an accelerator key. An accelerator key is a keyboard shortcut for a command. For example, if the display in the editor window is corrupted by the UNIX operating system or a server, you can refresh the editor window's screen display by pressing Control-l (lowercase L) or by executing the Edit > Redisplay command.


Editing Text

When an editor window opens, you can choose the commands from the Edit menu as illustrated in Figure 14.

Figure 14 Edit Menu

Effects of Edit Commands

With these commands from the Edit menu, you can:

Editor Modes

The Apex editor is always in one of two modes: edit mode or the default, read-only mode. When the editor is in edit mode, you can modify files. When the editor is in read-only mode, commands that modify files are inactive or grayed. To toggle between edit and read-only mode, select File > Edit or click the Edit button on the Button bar.


Moving the Cursor

The Apex editor cursor can be moved from its current insertion point by moving the mouse and clicking on the new insertion point or by a series of keyboard commands, as shown in Table 5.

Table 5 Cursor Control Commands
Cursor movement
Command
Backward one character
Control-b, ¨
Forward one character
Control-f, Æ
Up one line
Control-p, ¦
Down one line
Control-n, Ø
Backward one word
Control-Meta-b, Control-¨
Forward one word
Control-Meta-f, Control-Æ
To beginning of line
Control-a
To end of line
Control-e
Backward one paragraph
Meta-[, Control-Meta-[, Control-¦
Forward one paragraph
Meta-], Control-Meta-], Control-Ø
Up one full screen
Control-Meta-v
Down one full screen
Control-v
To beginning of file
Meta-, (unshifted <)
To end of file
Meta-. (unshifted >)
To beginning of selected text
Control-, (unshifted <)
To end of selected text
Control-. (unshifted >)

You can also:


Selecting Text

Cursor-movement commands used to select text are shown in Table 6.

Table 6 Cursor-Movement Commands for Text Selection
Selection extension
Command
Backward one character
Shift-¨
Forward one character
Shift-Æ
Up one line
Shift-¦
Down one line
Shift-Ø
Backward one word
Shift-Control-¨
Forward one word
Shift-Control-Æ
Backward one paragraph
Shift-Control-¦
Forward one paragraph
Shift-Control-Ø

A cursor-movement command that is executed with the Shift key pressed is called a selection command. When you execute a selection command, text is selected, or highlighted. When a section of text is highlighted, it is treated as a single unit by selection commands. Selection commands recognized by the Apex editor are listed in Table 7.

Table 7 Text Selection Commands
Selection with mouse
Action
Select a range of text
Either:
Select a word
Double-click on it
Select a line
Triple-click on it
Select all text
Quadruple-click
Shorten or extend the selection
Shift-left-click at the new beginning or end
Deselect the selection
Left-click outside the selection


Searching for Text

You can search for text that matches a specified string by choosing Search from the Edit menu or by using the keyboard shortcuts shown in Table 8.

Table 8 Keyboard Shortcuts for the Search Command
Search direction
Command
Forward (Edit > Search -->)
Control-s
Backward (Edit > Search <--)
Control-r

When you execute the Search command, Apex replaces the button bar with a special search panel in the editor window, as shown in Figure 15.

Figure 15 The Search Panel in the Editor Window

Conducting a Search Operation

The Search radio button must be selected. If the Search&Replace button is selected, Apex conducts a search-and-replace operation, which is described in Replacing Text.

To conduct a search:

1. Execute the Edit > Search command.

2. Type the pattern you want to search for in the text field to the right of the Search and Search&Replace radio buttons.

3. Click the --> button (or type Control-s) to start a forward search or click the <-- button (or type Control-r) to start a backward search. Repeat to continue searching.

4. Press Escape (or the Cancel key, if available) or click Done when you are finished searching, and Apex will remove the search panel and return the original button bar.

You can conduct as many searches as you like from the same search panel. To clear all text from the text field inside the search panel, click the Clear button. To view previously searched strings, click the History Icon to the right of the search-string text field (for more about the History Icon, see Using and Customizing the GUI).

When a Search Succeeds

When you execute the Search command, Apex begins its search at the current cursor position and proceeds to the end of the file (or the beginning of the file if you are searching backwards).

If its search succeeds, Apex highlights the first matching text it finds. Alternatively, you can highlight all text that matches your search criteria by clicking the Highlight All button in the search panel. The highlights remain until the View > Clear Messages command is issued or until the window is closed. When Highlight All is selected, the Next Message and Prev Message buttons move from one highlight to the next.

Search Options

To set special options for a search click the Options button in the search panel. Three check boxes appear:

Case-Sensitive and Whole-Word Searches

As an illustration of how these options work, suppose you search for the word "the" by entering "the" in the Search field. If you click neither Consider Case nor Whole Word, the word "Then" is recognized as a match for the pattern. But if you click either Consider Case or Whole Word (or both), "Then" is not a match for the "the" search field.

Using Wildcard Characters

When you choose the Wildcards option, special characters in your search string are interpreted as wildcards. Otherwise, all characters are interpreted literally.

Apex recognizes the regular expressions listed in Table 9. For more details, see the UNIX ed(1) manual page.

Table 9 Wildcard Characters
Wildcard
Pattern matched
.
Any single character
[ ]
Any single one of the characters listed between the brackets
*
Zero or more of the preceding single character
^
Beginning of line
$
End of line


Replacing Text

Instead of simply searching for a text string, you can replace it with a different string by clicking the Search & Replace radio button to the left of the search text field. Apex adds a second line of controls to the search panel, as shown in Figure 16.

Figure 16 Search and Replace Panel in the Editor Window

Conducting a Search-and-Replace Operation

The Search&Replace radio button must be selected. If the Search button is selected, Apex conducts a search operation, which is described in Searching for Text.

To conduct a search and replace:

1. Execute the Edit > Search command.

2. When the search-and-replace panel appears, enter a search string in the Search & Replace text field and a replacement string in the Replace with text field.

3. You can then search for the text in the Search & Replace text field by clicking the --> button for a forward search or the <-- for a backward search, just as if you were conducting a simple search.

4. When an occurrence of your search string has been found, it is highlighted. You can change the highlighted text by doing one of the following:

  • To replace the selected text with the text you have typed in the Replace with text field, click the Change button.
  • To replace the selected text with the text in the Replace with text field and then search for another occurrence of the text you have typed in the Search & Replace text field, click the Change & Search button.
  • To change all occurrences of your search text with the replacement text, from this match to the end of the file (if you were using a forward search) or to the beginning of the file (if you were using a backward search), click the Change All button.

5. Press Escape (or the Cancel key, if available) or click Done when you are finished searching, and Apex will remove the search panel and return the original button bar.

Search-and-Replace Options

The following options are available in search-and-replace operations:


Cutting and Pasting Text

You can remove selected text from the edit window and transfer it to an internal clipboard by choosing the Cut command from the Edit menu. You can then paste the text anywhere in your file.

You can also execute the Cut command by using one of the keyboard shortcuts listed in Table 10.

Table 10 Keyboard Shortcuts for the Cut Command
Cut
Command
Selected text
Shift-Delete, Shift-Backspace, Control-W
Next word
Control-Meta-d
Text from cursor to end of line
Control-k
All text on current line
Control-u

To copy selected text to the clipboard without removing it from the editor window, execute the Copy command. See Copying Text to the Clipboard.

To paste the most recently cut or copied text from the clipboard:

1. Place the cursor where you want to paste the needed text.

2. Select Edit > Paste or enter Shift-Insert.

You can also paste text from other windows, and even from other applications, that are running under the Motif window manager.

To do a Motif paste:

1. Place the mouse pointer where you want to paste the text.

2. Click the middle mouse button.


Copying Text to the Clipboard

To copy selected text to the clipboard without removing the text from the editor window, choose the Copy command from the Edit menu or execute the Control-Insert keyboard command.

When you have copied text to the clipboard with the Copy command, you can execute the Edit > Paste command to retrieve the text and paste it anywhere in an Apex window.

You can also transfer text stored on the clipboard to windows managed by other applications running under the Motif window manager. See Cutting and Pasting Text.


Deleting Text from a Document

To delete selected text from the edit window, choose Delete from the Edit menu or execute one of the keyboard shortcuts shown in Table 11.

Table 11 Keyboard Shortcuts for the Delete Command
Delete
Command
Previous character (or selected text)
Delete, Backspace
Next character (or selected text)
Control-d

When your executing the Delete command to delete text, the removed text is not copied to the clipboard and therefore cannot be recovered with the Paste command. To retrieve the deleted text, execute the Edit > Undo command. See "Recovering from Errors" on page 68.

The main purpose of the Delete command is to delete text from the Edit window without disturbing the current contents of the clipboard. With the Delete command, you can delete text that you are certain you want to delete permanently. Then you can replace the text you have removed with text that has previously been copied to the clipboard. This is a delicate operation that should always be conducted with great care.


Recovering from Errors

When you have executed an editing change by mistake, you can restore the edit window to the state it was in prior to your accidental editing change by choosing the Edit > Undo command or executing the Meta-Backspace keyboard shortcut.

You can also recover from earlier editing mistakes by executing the Undo command more than once.

If you execute the Undo command and want to reverse its effects, choose the Edit > Redo menu or execute the keyboard shortcut Shift-Meta-Backspace.

The Undo and Redo Commands

Each time you move the cursor Apex internally records that action in a set of changes. If a set of changes exists when the Undo command is issued, the command reverses the effects of the last change in that set of changes.

If you execute the Undo command twice, the second Undo command reverses the effects of the next-to-last change in the current set of changes. A third Undo command undoes the next change before that, and so on.

The effects of the Undo command end when there are no more editing actions to be undone. If there are no changes to be undone when you first execute the Undo command, Undo sounds a beep and takes no other action.

The Redo reverses the effects of the last Undo command. Although you can issue Undo commands until there are no more sets of changes to undo, you can execute only one Redo command to reverse the effect of any one Undo command. If you attempt to issue two Redo commands in succession, the second Redo command has no effect.

If you execute an Undo command and subsequently make an editing change, you cannot reverse your Undo command by executing Redo. If any editing changes have been made since the last Undo command was issued, Redo does not work.

However, you can continue to execute Undo commands until there are no more sets of changes to undo, and you can always reverse the effects of the last Undo command you issued by immediately executing a Redo command.

The Revert Command

You can also discard all the changes made since the last time a file was saved by selecting File > Revert. Revert loads the last saved contents of the file and clears its undo/redo sets of changes. You cannot undo Revert.


Using the Integrated Emacs Editor

The Emacs editor included with Apex is a version of GNU Emacs modified to be integrated with Apex. To use Emacs as your editor instead of the Motif text widget-based editors used by default with Apex, use the -emacs option to apexinit:

The integrated Emacs can be used for browsing/editing Ada and C/C++ code. The semantic functionality you get is the same as you get in the corresponding language-specific editor: Incremental parsing/pretty-printing, semanticize, navigation, show usage, etc. are all available in Emacs for Ada. Navigation (Visit/F5) runs off of extended tags information for C/C++.

The standard Apex menu items are all available in Emacs. Some additional Emacs-specific menu items are available at the bottom of some of the menus.

For a tutorial on using Emacs, execute the command C-h t within the integrated Emacs. The command C-h ? will give a list of help topics within Emacs.

For experienced Emacs users, using this integrated version of Emacs is the same as using the corresponding stand-alone release of GNU Emacs, except:

Using colors when displaying Ada and/or C/C++ Code

To get Apex emacs to use colors when displaying Ada and/or C/C++ code place the following lines in your .emacs file:

To do this from the toolbar within the emacs GUI select Help > Options > Toggle Global Font Lock.


Using Other UNIX Editors

Apex lets you use other UNIX editors —— for example, vi —— to write and edit programs. However, other editors do not let you take advantage of the language-specific features of the Apex editor. Commands such as Pretty Print, Show Usage, and Show Unused are not available in other UNIX editors. Also, Apex gives you the full benefits of optimal recompilation even when you use other UNIX editors to edit source files.

If you want Apex to use another UNIX editor by default, you can redefine the environment variable APEX_EDITOR using the following standard UNIX techniques:

You must do this before Apex is started.


Rational Software Corporation 
http://www.rational.com
support@rational.com
techpubs@rational.com
Copyright © 1993-2002, Rational Software Corporation. All rights reserved.
TOC PREV NEXT INDEX DOC LIST MASTER INDEX TECHNOTES APEX TIPS