Version 6.3.8 für Windows
 —  Editors  —

Creating and Modifying Source Code

The program editor supports bi-directional languages where text is written from right-to-left (for example, Arabic and Hebrew), and multi-byte character set languages such as Japanese and Chinese.

We recommend that you create source code in structured mode rather than reporting mode. Otherwise, you cannot use the expand/collapse editor feature (see Showing and Hiding Source Code).

For the differences between structured and reporting mode, see the section Natural Programming Modes in the Programming Guide. If you want to check whether structured mode has been activated or switch structured mode on, proceed as described in Programming Modes in the First Steps documentation.

For programming advice, see Using Context-Sensitive Help and the documentation in the Language section of the main overview page of Natural for Windows.

This section contains the following topics:


Entering and Inserting Text

You start entering text in the first line (numbered with 0010) of an empty editor window.

When you add lines to the source code of an object, Natural numbers the added lines in increments of ten. When you insert lines in source code, Natural numbers the inserted lines in increments of one. Upon saving the source code, Natural automatically renumbers all lines contained in the source code in increments of ten beginning with 0010 at the first line.

Apart from that, you can renumber all source-code lines any time by using the renumber command as described in Renumbering Lines.

Start of instruction setTo insert text

Top of page

Selecting Text

You can select one of the following:

Start of instruction setTo select a whole word

Start of instruction setTo select any portion of text

  1. Position the cursor on the first character to be selected by using either the left mouse button or the arrow keys.

  2. Drag the cursor to the last character to be selected by holding down the left mouse button or by pressing and holding down SHIFT and using the arrow keys.

    The selected text is highlighted.

  3. Release the mouse button or the keys.

Start of instruction setTo select the entire text

Start of instruction setTo deselect text

Top of page

Copying, Cutting and Pasting Text

The copy/cut and paste functions of the program editor are used to copy, move or delete text within a single object source or between multiple object sources (see also Dragging and Dropping Text).

It is possible to revoke a cut or paste operation after it has been performed. See Undoing or Redoing Modifications.

If you want to create data fields, as an alternative to using copy and paste, you can import fields from another source object as described in Importing Data Fields.

Start of instruction setTo copy or cut and paste text

  1. Select the text you want to copy or cut by proceeding as described in Selecting Text.

  2. From the Edit menu, choose Copy or Cut.

    Or:
    Choose either of the following toolbar buttons:

    graphics/pgm_win_copy.png (Copy) or graphics/pgm_win_cut.png (Cut)

    Or:
    Press CTRL+C (to copy) or CTRL+X (to cut).

    The selected text is placed on the clipboard and can be pasted in the source code contained in the active object window.

  3. If the text is to be pasted in another object source, open the respective source.

  4. Position the cursor on the source-code line above which the copied or cut text is to be pasted.

  5. From the Edit menu, choose Paste.

    Or:
    Choose the following toolbar button:

    graphics/pgm_win_paste.png

    Or:
    Press CTRL+V.

    The text is pasted at the specified position in the source code contained in the active object window.

  6. If you want to paste the same text again, repeat Steps 4 and 5.

Top of page

Dragging and Dropping Text

Drag-and-drop operations can be used to move or copy text. The drag source and drop target may be Natural Studio or a different application that supports drag-and-drop.

It is possible to revoke a drag and drop operation after it has been performed. See Undoing or Redoing Modifications.

Start of instruction setTo move or copy text using drag-and-drop functionality

  1. Select the text you want to move or copy (see also Selecting Text) and position the mouse pointer anywhere in the selected (highlighted) text.

  2. Press and hold down the left mouse button and move the mouse. In addition, hold down CTRL if you want to copy the text instead of moving it which is the default.

    The mouse pointer changes to an arrow pointer inside a rectangle indicating that drag-and-drop editing is enabled. For a copy operation, a plus sign (+) is attached to the rectangle. A text insertion caret next to the arrow pointer indicates the position where the selected text can be dropped.

    If the mouse pointer changes to a "no drop" pointer (slashed circle), the current target location does not accept a drop. This happens when you attempt to insert text into protected source code (see also Protecting Source-Code Lines) or when the drop target has no drag-and-drop capabilities. If you execute a move operation on protected source code, the text will be copied rather than moved to the target location.

    You can press ESC if you want to cancel drag-and-drop editing.

  3. Release the mouse button where you want to drop the text.

    The selected text is dropped at the current position of the caret.

    If the mouse button is released when the "no drop" pointer is visible, the drag-and-drop operation is canceled.

Top of page

Undoing or Redoing Modifications

The editing actions you perform in the editor window can be revoked by using the Undo command or redone (after being undone) by using the Redo command. The Undo or Redo command applies to any source-code modifications that are not made via the command line (for example, RENUMBER or STRUCT).

The number of actions which can be undone or redone is determined by the value specified in the preferences for the program editor and is limited by the memory allocated: see the editor options Max undo mem (MB) and Max no of undo described in Program Editor Options in the Using Natural Studio documentation.

The undo/redo buffer is cleared when you close the editor window.

Undo operations restore line numbering to its status before the operation. Redo operations restore line numbering to its status before the previous undo operation.

Start of instruction setTo undo an action

Start of instruction setTo redo an action that has been undone

Top of page

Deleting Text

When you delete text, it is cut from the object but is not placed on the clipboard. The only way to recover deleted text is by undoing the delete operation. See Undoing or Redoing Modifications.

Note that when text is deleted from a source, no warning is provided.

Start of instruction setTo delete text

  1. Select text by proceeding as described in Selecting Text.

  2. From the Edit menu, choose Delete.

    Or:
    Choose the following toolbar button:

    graphics/pgm_win_delete.png

    Or:
    Press DEL.

    The text is deleted from the source code contained in the active object window.

Top of page

Adding and Removing Comments

You can mark or unmark an entire source-code line as a comment line or place a commentary text within a line.

Start of instruction setTo add a comment line

Start of instruction setTo append a comment to a statement

Start of instruction setTo mark lines as comment lines

  1. Place the cursor anywhere in the source-code line you want to mark.

    Or:
    Select one or more source-code lines as described in Selecting Text.

  2. From the Edit menu, choose Advanced > Add Comment Mark(s).

    Or:
    Press CTRL+M.

    A comment mark (*) followed by a blank character is added to the beginning of the specified source-code line(s).

Start of instruction setTo unmark lines as comment lines

  1. Place the cursor anywhere in the comment line you want to unmark.

    Or:
    Select one or more source-code lines as described in Selecting Text.

  2. From the Edit menu, choose Advanced > Remove Comment Mark(s).

    Or:
    Press CTRL+SHIFT+M.

    A comment mark (* , ** or /*) is removed from the beginning of the specified source-code line(s).

Top of page

Renumbering Lines

Start of instruction setTo renumber source-code lines

Related Topic:

Top of page

Translating to Upper or Lower Case

You can translate source code from upper to lower case or from lower to upper case.

Start of instruction setTo translate text from upper to lower case or vice versa

  1. Select the text you want to translate as described in Selecting Text.

  2. From the Edit menu, choose either Advanced > Upper Case or Advanced > Lower Case.

    Or:
    Press CTRL+SHIFT+U for upper case or CTRL+SHIFT+L for lower case.

You can switch automatic upper-case translation on by setting the corresponding editor option as described in Program Editor Options in the Using Natural Studio documentation. With automatic upper-case translation, the entire source code (except commentary text) is translated to upper case whenever you save, check or catalog the source code. Automatic upper-case translation is useful in a remote environment on a mainframe computer where the LOWSRCE (Allow Lower-Case Source) compilation option is set to OFF. For details, see LOWSRCE in COMPOPT in the System Commands documentation for mainframes.

Top of page

Using Automatic Line Breaks

The program editor provides the option of inserting automatic line breaks at a specified column while editing text or after selecting existing text.

The following rules apply when this option is active:

Start of instruction setTo activate automatic line breaking

Start of instruction setTo insert automatic line breaks for existing text

  1. Select the desired text section.

  2. From the Edit or context menu, choose Advanced > Break at Ruler position.

    Automatic line breaks are inserted into the text according to the rules described earlier.

Top of page

Converting to and from Hexadecimal Format

The program editor provides options to display the hexadecimal Unicode format of characters contained in a text constant and to convert these characters to their equivalent hexadecimal format. You can convert characters either to hexadecimal code page format or hexadecimal Unicode format, or vice versa. For conversion to hexadecimal code page format, the code page defined for the source is used. If no code page is defined for the source, the code page defined for the current Natural Studio session is used.

Start of instruction setTo display hexadecimal Unicode format

Start of instruction setTo convert characters to hexadecimal format

  1. For hexadecimal code page format, select single or multiple characters from a text constant and press CRTL+ALT+X.

    Or:
    For hexadecimal Unicode format, select single or multiple characters from a text constant and press CRTL+ALT+U.

  2. The selected character(s) are replaced by the equivalent hexadecimal format as shown in the Unicode example with the Greek letters ΩΣΔΠΨ below:

    For hexadecimal code page format: a character that cannot be converted will be replaced by the substitution character of the defined code page.

  3. Place either of the following prefixes before the apostrophe that precedes the constant:

    The constant must start with the hexadecimal value as shown in the Unicode example below:

    Therefore, if you only convert part of a text constant, you may have to split the constant into multiple constants to avoid syntactical errors as shown in the Unicode example below:

Start of instruction setTo convert hexadecimal to character format

Top of page

Recording, Replaying and Saving Keystrokes

The keystroke recorder records and replays only input from the keyboard; mouse movements and operations are ignored. The keystroke sequence recorded last is retained for the duration of the Natural Studio session. The keystroke sequence can be saved as a macro for permanent use during any subsequent sessions.

This section contains the following topics:

Recording and Replaying Keystrokes

Start of instruction setTo record a keystroke sequence

  1. Place the cursor at the position where you want to begin recording.

  2. From the Tools menu, select Macros > Start Recording.

    Or:
    Choose the following toolbar button:

    graphics/pgm_win_start_record.png

    Or:
    Press CTRL+SHIFT+R.

    The mouse pointer changes to an arrow pointer with a symbol illustrating a cassette tape. This indicates that recording is in progress.

  3. Press the keys in the sequence you want to record.

Start of instruction setTo stop recording

Start of instruction setTo replay a recorded keystroke sequence

  1. Place the cursor at the position where you want to begin replaying the recording.

  2. From the Tools menu, select Macros > Replay Recording.

    Or:
    Choose the following toolbar button:

    graphics/pgm_win_replay.png

    Or:
    Press CTRL+SHIFT+P.

    The keystroke sequence recorded last is replayed.

Handling Macros

You can save a recording as a macro, which can be used permanently, in any Natural Studio session. You can add a most frequently used macro or a macro command to the toolbar or menu bar or create shortcuts. You can overwrite macro code or delete a macro that is no longer required.

Start of instruction setTo save a recording as a macro

  1. When you have stopped recording, from the Tools menu, choose Macros > Save Macro.

    The Save Macro dialog box appears.

  2. In the Name box, type a name of up to 32 characters and choose OK to save the macro.

    If a macro with the specified name already exists, an appropriate message appears asking whether to overwrite the contents of the existing macro or save the macro under a different name: choose Yes to overwrite or No to rename the macro.

    The macro is saved under the specified name, added to your user profile and listed in the Macros submenu of Tools.

    You can save a maximum of 16 macros.

Start of instruction setTo run a macro

  1. From the Tools menu, choose Macros.

    All macros saved in your user profile are listed in the submenu.

  2. From the macro list, choose the required macro.

    The macro is executed and replays the recorded keystroke sequence.

Start of instruction setTo delete a macro

  1. From the Tools menu, choose Macros > Delete Macro.

    The Delete Macros window appears with a list of all macros saved in your user profile.

  2. Select the macro you want to delete and choose Delete.

    The macro is deleted from the list.

  3. Choose OK to confirm the action and remove the macro from your user profile.

    Or:
    Choose Cancel to exit the dialog box without any action.

Start of instruction setTo add a macro or a macro command to the toolbar or menu bar

  1. Invoke the Customize dialog box and open the Commands page as described in Customizing Natural Studio in the Using Natural Studio documentation.

  2. From the Categories drop-down list box, select Tools.Macros.

    All macro commands and available macros are listed in the Commands list box.

  3. Select a command or a macro and drag it to the menu bar. For detailed instructions, see Customizing Natural Studio.

Start of instruction setTo assign a shortcut to a macro or a macro command

  1. Invoke the Customize dialog box and open the Keyboard page as described in Customizing Natural Studio.

  2. From the Categories drop-down list box, select Tools.Macros.

    All macro commands and available macros are listed in the Commands list box.

  3. Select a command or a macro and press the key combination you want to assign as a shortcut to the selected command or macro. For detailed instructions, see Keyboard in Customizing Natural Studio.

    The keyboard shortcut is now assigned to the macro or macro command and appears next to the associated macro command or macro name listed in the Macros submenu of Tools.

Top of page

Protecting Source-Code Lines

You can protect a single source-code line or a block of source-code lines against unauthorized modification by using read-only tags.

Protected source-code lines cannot be edited. In addition, you cannot add lines to the beginning or end of source code where a protected block of lines starts in the first line (0010) and ends in the last (here: 0090) as shown in Example of Line Protection. You can only add lines if the protected block is preceded or followed by an unprotected line.

The following editor functions cannot be performed on protected source-code lines:

Warning:
Read-only tags cannot be modified or deleted once the respective source object has been reloaded into the source buffer.

Read-only tags are stored in the source object in the Natural system file. They are removed from the source buffer and are therefore hidden when the respective source object is reloaded into the source buffer. A source object is reloaded into the source buffer, for example, when you execute a system command such as STRUCT or RENUMBER on the source, or when you open the source object in the editor window.

You can exclude protected source-code lines from structural indentation by proceeding as described for the STRUCT command under Indentation of Source Code Lines in the System Commands documentation.

In a reloaded source object where read-only tags are hidden, protected source-code lines are grayed out as shown in Example of Line Protection. (You can specify a different background color by changing the color definition as described in Program Editor Options in the Using Natural Studio documentation.)

Start of instruction setTo protect a single line

Start of instruction setTo protect a code block

  1. At the end of the line where the block to be protected begins, enter a blank character and append the following tag:

    /*<RO>>
  2. At the end of the line where the block to be protected ends, enter a blank character and append the following tag:

    /*<<RO>

Read-only tags are reinserted into the source buffer whenever you save the source object. You can prevent read-only tags from being reinserted by proceeding as described below.

Start of instruction setTo stop reinsertion of read-only tags

Example of Line Protection

In the example of a source object below, the lines of the DEFINE DATA statement and the consecutive comment lines are protected with read-only tags. The tag /*<**> guarantees that the read-only tags are not reinserted into the source buffer.

Read-only tags are hidden when the source object is reloaded into the source buffer as shown in the example below. Protected lines are grayed out.

Top of page