Checking Out the Menus

# Checking Out the Menus

You've already seen that Alice uses menus for a large number of things. The most important menus are the ones that contain the commands of Alice. We're going to look at these in this chapter. We'll be using the `squares` program in our examples again, so you should load the program in when you start Alice up.

Every Alice command can be found on at least one command menu, and some commands appear on more than one. Every command can be executed from a menu in addition to any other ways of issuing the command.

For example, you can SAVE a program by pressing `[ALT-S]` or by choosing the `Save` selection from the Files Menu. Which way is better? They're both the same. If you remember that `[ALT-S]` means `Save`, it's the fastest way to save your program. If you forget what you have to push to save a program, you can always call up the Files Menu and choose `Save` from that.

A natural question: what happens if you forget what you have to push to call up the Files Menu? That's answered in the next section.

## The Master Menu

Press `[F7]`. This produces the Master Menu. If you remember this key, you'll be able to get at all the other menus of Alice. (In fact, if you work at it, you can do 90% of all your programming with just `[F10]`, `[F7]`, and the arrow keys, selecting everything you can from menus. Of course, this wouldn't be very fast...)

Looking at the Master Menu, you see that there are really quite a number of menus available.

Screen Shot mastmenu not available

Some of these you already know about. For example, choose the `File Operations` selection. You should recognize this as the Files Menu. You get exactly the same thing if you press `[F8]` -- try it.

Call up the Master Menu again and this time choose the `What can I type here?` selection. You'll get an Input Menu, the same thing that you'd get if you chose

>     What can I type here?

from the Help Menu or if you pressed `[ALT-T]`. Similarly, if you choose

>     Information about Pascal

you get the same thing that you get if you choose `Information about Pascal` from the Help Menu or if you pressed `[ALT-P]`. Again, prove this to yourself by trying it.

The other entry on the Master Menu that you already know about is

>     Possible Symbols

This gives you the same kind of symbol list that you get by pressing `[END]`.

When you get rid of the selections we've already talked about, the Master Menu reduces to this.

>     Insertions
>     Deletions
>     Change Structures
>     Move Cursor
>     Misc
>     Running the Program
>     Special Changes

In the rest of this chapter, we'll talk about these different menus.

## The Deletion Menu

You get the Deletion Menu by selecting the `Deletions` entry from the Master Menu. You can also get the menu by pressing `[F3]`. Press `[F3]` now to have a look.

Screen Shot delmenu not available

You already understand what `Clip` does. In the same way, `Delete` is the DELETE command that you get when you press `[DEL]`.

Try these things out, just to make sure. Choose the `Do nothing` option on the menu to get back to your program. Move the cursor to the argument `i*i` of the `writeln` instruction. Press `[F10]` and move the cursor if the argument isn't completely highlighted. Make sure you only highlight the `i*i`. Press `[F3]` to call up the Deletion Menu. Choose the `Delete` selection from this menu. Alice will get rid of the menu and you will see that the highlighted material has been deleted. Remember that DELETE doesn't leave a placeholder behind unless the placeholder is necessary for a correct program.

UNDO the deletion by pressing `[CTRL-U]`. You'll see the deleted `i*i` reappear. Now, CLIP out the `i*i`. You do exactly the same thing we did before, only this time you choose the `Clip` option from the Deletion Menu instead of `Delete`. The `i*i` is deleted again, but this time a `Value` placeholder is left behind.

You might ask, ``Why would I want to use the Deletion Menu when pressing `[CTRL-P]` or `[DEL]` is so much faster?'' Good question. If you can remember which button to push, pushing `[CTRL-P]` or `[DEL]` is faster. But what happens if you can't remember the right key? You can still work from the Menus, and that's the whole point.

It's also important to realize that some commands can't be executed just by pressing one or two keys. Some commands have to be executed from the menu (or in a third way that we haven't talked about yet). The `Raise` selection on the Delete Menu is an example of this sort of command.

In your program, highlight the for loop and its contents by moving the cursor to the for and pressing `[F10]`. Call up the Deletion Menu by pressing `[F3]` and choose the `Raise` selection. Notice what happens: the enclosing for statement disappears and the `writeln` that was inside is raised one level of indentation. In other words, `Raise` gets rid of a construct like for or if that encloses a number of statements. You have to highlight the enclosing statement before you can raise the contents.

Press `[CTRL-U]` twice to undo what we just did. We'll want the program in good shape for the sections to come.

The `Clear this workspace` gets rid of your current program and gives you a new empty program template. You can't UNDO this, so make sure you've saved your current program before you perform this operation.

The `Recover memory` selection cleans things up inside Alice to provide more memory for various purposes. The `Recover memory` command throws away all extraneous data stored in memory. In particular, it throws away all the information that is saved so that UNDO will work. This frees up a lot of memory but also means that you can't UNDO instructions that happened before the `Recover` operations. Alice warns you that this is the case.

We aren't going to talk about the `Move to workspace` selection just now -- we'll save that for next chapter when we talk about workspaces.

## The Insertion Menu

You get the Insertion Menu by selecting the `Insertions` entry from the Master Menu. You can also get the menu by pressing `[F4]`. Press `[F4]` now to have a look.

Screen Shot insmenu not available

The `Extend list` selection works exactly the same way as pressing `[CTRL-E]`. Move the cursor to the word `writeln` in the sample program, then press `[F4]` and select `Extend list`. You will see that Alice adds a new `Statement` placeholder after the `writeln` instruction. In the same way, `Insert` works the same way as pressing `[INS]`. Move the cursor to the word `writeln`, press `[F4]` and select `Insert`. You will see that Alice adds a new `Statement` placeholder before the `writeln` instruction.

Press `[F4]` again and this time choose the `Possible Symbols` selection. This provides a Symbol List in the same way that pressing `[END]` does. If you choose `What can I type here?` from the Insertion Menu, you will get the same sort of Input Menu that is provided by pressing `[ALT-T]`.

The only things on the Insertion Menu that we haven't talked about yet are the `Enclose` and `Get workspace` selections. We'll talk about `Get workspace` in the next chapter. As for `Enclose`, why don't you see if you can understand how it works on your own? To get an explanation of this option, do what you always do: press `[F9]`. In this case, highlight the `Enclose` option on the menu and then press `[F9]` instead of another key. This will give you an explanation of what the command does. (Hint: it's the opposite of `Raise` on the Deletion Menu.)

## The Change Menu

You can get the Change Menu by choosing `Change Structures` from the Master Menu or by pressing `[F5]`. We aren't going to talk about anything on the Change Menu right now because we're saving it for the next chapter. However, if you want, you can call up the menu, highlight any selection on it, and press `[F9]` to get a description of what each command does.

## The Move Menu

The Move Menu contains a number of commands for moving the cursor around in your program. You can get the Move Menu by choosing `Move Cursor` from the Master Menu or by pressing `[ALT-G]`.

Screen Shot movemenu not available

The `Mark Position` selection allows you to record a particular cursor location so that you can get back to it easily later on. To show how this works, move the cursor to the first actual instruction of your program (the one after the keyword begin). Press `[ALT-G]` to call the Move Menu, then choose `Mark Position`. At the bottom of the screen, you will see Alice type

>     Mark?

Alice wants you to give a name to this mark. The name of a mark is just a single letter, so let's call this one ``A''. Enter an ``A'' in response to `Mark?` -- you do not have to press `[ENTER]` after.

You won't see anything change in your program, but this cursor position is now marked with the name ``A''. To see that this is true, move the cursor anywhere else in the program. Next, press `[ALT-G]` and choose `Go to mark`. Alice will ask `Mark?` again. Enter ``A'' -- this says you want to go to mark ``A.'' The cursor will jump back to the position you marked.

The `Former cursor loc` selection is another way of jumping to an old cursor position. The cursor will jump to the position it had before the last command from the Move Menu. Try it -- press `[ALT-G]`, and choose `Former cursor loc`. You'll see the cursor jump back to its previous position. Do it again, and the cursor will jump back to its second most recent position.

The `Go to declaration` command is useful when you want to check or change the declaration for a symbol (e.g. a variable). Place the cursor on a symbol name, then choose this command from the Move Menu. Alice will move the cursor up to the declaration for the symbol. When you are done looking at this declaration or changing it, you can get back to your former position with the `Former cursor loc` selection.

The `Page down` selection moves the cursor forward in your program. The distance it moves is about equal to the amount of material that can be shown on the terminal display screen. This allows you to ``page'' quickly through your program. You can also ``page down'' by pressing the `[PgDn]` key on the PC. The `Page up` selection is similar, but moves the cursor backwards. You can also ``page up'' by pressing the `[PgUp]` key on the PC.

The `Up to Parent` selection jumps to the start of whatever contains the current cursor location. For example, if the cursor is on the `writeln` of

>     for i := 1 to 10 do begin
>         writeln(i,i*i);
>         end;

choosing the `Up to Parent` selection would go to the for that contains the `writeln` instruction. You can also get this effect by pressing `[CTRL-6]`. (You can remember this by thinking that the ```^`'' on the 6 key points up.)

The `Top of Block` selection goes to the start of the program or subprogram that contains the current cursor location. You can also get this effect by pressing `[HOME]`.

This only leaves us with the `Search` commands. These allow you to search for strings of characters in your program. For example, suppose you want to find the next line that the variable `hello` is used in your program. You would begin by choosing the `Search Forward` selection from this menu. Alice would ask you what you wanted to search for and you would answer

>     hello

(then press `[ENTER]`). Alice would then look for the next instance of this string in your program. You can get the same effect by pressing `[CTRL-F]`.

`Search backward` works the same way except that it looks backward through your program instead of forward. `Search again` searches for the last string that you were searching for. The search goes forward if the previous search was forward, and backwards otherwise. For example, if you wanted to search for the third occurrence of `hello` in your program, you might press `[HOME]` (to get to the start of the program), `[CTRL-F]` (to find the first occurrence), type in `hello` followed by `[ENTER]` to tell what you want to find, then use the `Search again` command twice.

Any time you issue a search command, it will indicate a default string to search for. This default will always be the last string you searched for. If you want to search for this default string, just press `[ENTER]`; otherwise, enter the string you want to look for.

## The Run-Time Menu

The Run-Time Menu (also called the Debugging Menu) contains a number of commands that help you debug and run your programs. You can get the Run-Time Menu by choosing `Running the Program` from the Master Menu or by pressing `[F6]`.

The entries on the Run-Time Menu will change, depending on how you have things set up. For example, there is an entry on the Run-Time Menu that turns debugging features on or off. If you have the debugging features on, the entry on the menu will let you turn them off. There's no point having an entry for turning these features on, because they already are on. If the debugging features are off, the entry on the menu will let you turn them on.

In this way, the selections on the Run-Time Menu depend on what you're doing. We'll give you a list of the possibilities here, but don't expect to see all of these when you press `[F6]`. Also note that this is not the order that the selections will be shown.

>     Big Step
>     Cursor Following Off
>     Cursor Following On
>     Clear Point
>     Continue
>     Debug on
>     Debug off
>     Execute statement
>     Immediate mode block
>     Pop suspended state
>     Pop suspended & Run
>     Run Program
>     Set Breakpoint
>     Single Step
>     Typecheck program
>     Who called me?
>     Write Output to Log File
>     Don't Write Output to Log File

The `Run Program` selection runs your program in the same way that pressing `[F1]` does. The `Single Step` selection lets you single-step through your program. It is much easier to press `[F2]` again and again than to choose this selection from the Run-Time Menu every time you want Alice to execute another instruction; nevertheless, you can do this if you want.

The `Cursor Following On` selection is an interesting one. However, the program we're working with right now won't show how it works very well, so load the program ``sieve.ap'' from your Alice supplement disk (use the LOAD command). This program prints out the first few prime numbers.

Call up the Run-Time Menu by selecting it from the Master Menu or by pressing `[F6]`. Highlight the selection `Cursor Following On` and press the SPACE bar. Now, run your program by pressing `[F1]` or by choosing the `Run Program` selection from the Run-Time Menu. Alice will divide the screen into a source code half and an output half, the way it does when you are single-stepping. Watch what happens to the cursor on the screen. When Alice runs the program, it will move the cursor through your source code on the screen, showing you the instructions it is executing as it does them. In this way, you get a picture of your program as it runs. Run the program several times to make sure you see what's happening.

To turn off cursor following, call up the Run-Time Menu again and choose the `Cursor Following Off` selection. You can also choose the `Debug off` selection; this turns off cursor following and also gets rid of the ``split screen'' effect.

The `Continue` selection from the Run-Time Menu is a little tricky. We'll describe it in the next chapter.

## The Miscellaneous Menu

You can call up the Miscellaneous Menu by choosing the `Misc` entry of the Master Menu or by pressing `[SHIFT-F9]`. The menu has the following entries.

Screen Shot miscmenu not available

The `File I/O` selection just calls up the Files Menu, the same way that `[F8]` does. The `Redraw Screen` selection rewrites everything that should be on the screen; this takes care of a few rare problems that foul up the screen display. The `Autosave` selection sets things up so that your program is automatically saved every time you change something in it (so that you don't have to use the SAVE command very often). As for the `Change Workspace` and `Immediate` selections, we'll talk about them in the next chapter. `Special Changes` are discussed in the next section, so that just leaves us with `Set Macro`.

The `Set Macro` selection lets you associate a series of keystrokes with a single key sequence. Once you've done this, you can type the key sequence any time in your Alice session and it will have the same effect as typing all the associated keystrokes.

For example, suppose you use `readln` instructions a lot and you want to save yourself some typing. You decide to associate the string of characters `readln(` with the single key R (upper case). To do this, press `[SHIFT-F9]` to summon the Miscellaneous Menu and choose the `Set Macro` selection.

Alice will first ask you for the single key sequence. You enter the upper case R. Next, Alice will ask you for the string of characters that should be associated with this sequence. You will type

>     readln(

followed by `[ENTER]` to show the end of the string. From this point onward, you can type R whenever you want to enter `readln(`. Try it and see. Move to a blank `Statement` placeholder, and enter `R`.

## Other Menus

The Special Changes Menu listed in the Master Menu and several other menus contains commands that change one type of construction into another. For example, you can change an if statement into a while loop through the Special Changes Menu. Just put the cursor on the statement that you want to change and then call up the Special Changes Menu. You will be offered a list of the new statements that the old statement can become. Choose one of these, and Alice will make the change.

There is also a menu called the Select Menu, called up by pressing `[SHIFT-F10]`. This provides commands that can be applied to ranges that you have swept out; it is located on `[SHIFT-F10]` for convenience. All the commands on this menu are found on other menus too, so we won't talk about them here.

## Chapter Summary

In this chapter, we talked about

1. The Master Menu, called up by pushing `[F7]`. Most other menus can be obtained by selecting entries from the Master Menu.
2. The Deletion Menu, called up from the Master Menu or by pressing `[F3]`.
3. The Insertion Menu, called up from the Master Menu or by pressing `[F4]`.
4. The Change Menu, called up from the Master Menu or by pressing `[F5]`.
5. The Move Menu, called up from the Master Menu or by pressing `[ALT-G]`.
6. The Run-Time Menu, called up from the Master Menu or by pressing `[F6]`.
7. The Miscellaneous Menu, called up from the Master Menu or by pressing `[SHIFT-F9]`.
8. The Special Changes Menu, called up from the Master Menu or several other menus.