Classic Computer Magazine Archive COMPUTE! ISSUE 52 / SEPTEMBER 1984 / PAGE 132

Apple Editing Hints

Patrick Moyer

Most computer owners develop a love-hate relationship with at least one feature of their machines. For Apple owners, this feature is often the editing functions. Here is a review of Apple editing controls and protocols and some tips on making the process easier and more effective.

The Apple uses a combination of screen editing and line editing. Changes are made by moving the cursor to a particular line which has been listed on the screen and retyping that line. This retyping is usually accomplished with the right arrow key. As the right arrow is pressed, the cursor moves to the right, reentering all it passes over. A change is made by typing over what is already there, or by inserting the correction through a combination of cursor moves.

Physical, Logical

Therefore, to make a change, we must specify the line to be changed. In this case, we are talking about a line of BASIC, not a line displayed on the screen. The BASIC line is called a logical line, as opposed to the physical line that is displayed on the screen. A logical line may contain multiple BASIC commands and may be up to 255 characters long. The physical display line is the 40-letter width of the screen.

Before a BASIC line can be changed, it must be listed. It is best to clear the screen with the HOME command initially. This eliminates confusion about what was changed and what wasn't.

When a line is listed, the computer puts one space between words or variables, two spaces after the line number, seven spaces at the end of the first physical line, and five spaces on the right and left sides of the remaining physical lines.

Most of the time, these extra spaces and lines are of little consequence. One can just merrily right-arrow over them with no harm. The one exception occurs in string information (characters in quotes). This causes a problem. If a string is broken between two or more physical lines during the listing process, and you right-arrow to retype, 12 additional spaces will be inserted between the last character on the first line and the first character on the next line. Certainly not what's wanted. The common solution is to avoid the right arrow and use the cursor with the <ESC>K sequence instead.

Simplified Cursor Control

There's an even simpler solution. Let's edit a line step by step to demonstrate this technique (<ESC> is the ESC KEY, <RET> is the RETURN KEY):

Here's the line as originally typed:

10PRINT "THIS IS A LONG LINE OF STRING DATA" <RET>

List the line. It looks like this:

LIST10<RET>
10 PRINT "THIS IS A LONG LINE OF STRING DATA"

We then type <ESC>I, repeating the I key until the cursor is over the second digit of the line number; J is pressed to move the cursor one space to the left. (This J keypress is important. If you forget it and continue the editing process, you will gain a line in your program. Line 0 will be created, but more about that later.)

Once you've moved left, leave <ESC> mode. This is done by pressing any key not having meaning in <ESC> mode. Because some keys not normally used for cursor movement do have special meaning, it's best to press the space bar. Remember, this will not move the cursor.

We can now use the right arrow to "retype" the line to the place of the change. The repeat key can be used to speed this process. Let's say you've used the right arrow until it appears after the last quote. The line on the screen looks no different. However, if we LIST the line, we now see this:

10 PRINT "THIS IS A LONG LINE OF STRING DATA"

If we type RUN we get:

RUN<RET>
THIS IS A LONG LINE OF STRING DATA

Eliminating Problem Margins

The common solution, again, is to right-arrow to the R in STR, then type <ESC> and press K repeatedly to move the cursor until you reach the I in ING. Anyone who has done this often will know how easy it is to forget <ESC> K, and end up with a string of K's.

The solution is simply to eliminate those extra margins unless you need them. Let's start with the same original line:

10 PRINT'THIS IS A LONG LINE OF STRING DATA"<RET>

To edit the line we type:

HOME : POKE33, 30 : LIST10<RET>

The HOME gives us a clean screen to work with; the LIST puts the line to be edited on the screen. A POKE instruction places a single number into an "address" in the computer's memory. Address 33 controls the width of the screen display. Placing the number 30 in it reduces the size of the screen to 30 characters wide rather than 40.

Caution: The POKE must be done before the LIST for this method to work. The HOME is optional, but prevents a very confusing screen. (Try it. You'll see what I mean.) The screen will erase and display:

10 PRINT"THIS IS A LONG LINE OF STRING DATA"

As you can see, the line is 30 characters wide without the extra margin spaces. Move the cursor to the line number as usual. The right arrow may be used without ill effect. It will go directly from the S on the first display line to the T on the second line without inserting any blanks. This eliminates the need to use the <ESC> K sequence.

Once you have finished editing, you will need to type TEXT. This command will return you to normal 40-character screen mode.

Duplicating Lines

One strength of Apple II editing is the ability to duplicate lines. Let's try an example:

HOME : POKE33, 30 : LIST10<RET>
10 PRINT"THIS IS A LINE TO BE DUPLICATED"

Next move the cursor up to the line using the normal <ESC>I. When the cursor arrives over the number, move it left until it is over the first digit of the number. Then press the space bar as before; but prior to using the right arrow, retype the line number, say, 20. Then use the right arrow to "retype" the line as described above until you reach the end of the logical line. At this point, press RETURN. If you LIST the program, you'll see:

HOME : POKE33, 30 : LIST<ret>
10 PRINT"THIS IS A LINE TO BE DUPLICATED"
20 PRINT"THIS IS A LINE TO BE DUPLICATED"

Once you have moved your cursor up to the number and changed it, you do not have to reuse the entire line. You can treat it like any line to be edited further if necessary.

Easy Program Merge

This technique can also be used on a limited scale to merge two programs. Let's say you have a favorite subroutine of three or four lines which you wish to add to a program. You could use the merge function of the Renumber program on the Systems Master, or the program that is part of the Programmer's Toolkit. If you don't have these programs or you don't have them handy, here is a simple procedure:

  1. Save the program you are working on.
  2. Load the program which contains the lines to be copied to your new program.
  3. Clear the screen, change width, and list lines (using HOME : POKE33,30 : LIST statements).
  4. Now, load the program the lines are to be added to.
  5. Using the normal <ESC> and right-arrow commands, edit each line without changes. It's best to edit the last line first and work up the screen, entering each line one at a time. This is because when multiple lines are listed and edited, once <RET> is pressed, the line number below it is partially destroyed and has to be retyped by hand. There's nothing wrong with changing the line numbers to fit your new program if the current line numbers are a problem.
  6. Once all lines are edited, save the program. If you list it, you'll find the lines are now part of your program.

Finally, if you want to cancel a particular change as long as you have not pressed <RET> yet, cancel the editing of the line by typing <CTL> X. Be sure that you press the <CTL> key first, then X. The machine will answer with a backward slash. If you list the line, it will be unchanged.