Using EMACS for Pascal Programming

Below you will find instuctions on using emacs to write Pascal programs:


Starting emacs

To start the emacs text editor, you "call" it from a command or shell tool window. Do the following: Type emacs lab-2.pas now.

A new window will appear on your screen. The window is the emacs text editor window. This window will be used to type in your programs for this class. In the window you have on your screen, you will see a complete pascal program. Scroll around the window using the scroll bar on the far right edge of the window. You may also use the arrow keys to move around inside the window. Make sure that you have selected this window before you move around the window.

Take a look at the structure of the program. Do you have a guess as to what the program will do?

Working in emacs

The following pointers will help you to more effectively create your Pascal program codes.

Buffers in emacs

There are three different buffers that you will need to work with while using emacs. The first buffer, called the main buffer, is used for editing your pascal program. At the bottom of the emacs editor is a mini buffer. This buffer is used for keying in commands for different purposes such as compiling your pascal program and exiting emacs. The third buffer, which will only appear after a compilation attempt and will appear in the middle of the emacs screen, is called the execution buffer. This buffer is used to show the results of the compilation attempt. Any compilation errors will be listed here. An important note is that only one of the buffers can be active at a time. Make sure you have the correct buffer active before working in emacs. For instance, make sure the main buffer is active before trying to edit your pascal code. To make a particular buffer active, using the mouse, place the pointer inside that buffer and click once on the select button. Another special note is how to get rid of the execution buffer. To do this, simply place the pointer on the bar separating the execution buffer from the main buffer and press the middle button on the mouse once.

Reformat your work

At times it may be useful to reformat your Pascal program so that it becomes more easily read. To reformat your program, do the following: This should reformat your Pascal program so that proper indention is achieved.

Let's try this. First we need to "mess up" the indentation of the program that you see before you. Move the cursor (using either the mouse or arrow keys) to the line that is directly below the line

var { declaration of Variable names }

Remove the spaces that are at the beginning of the line. The line should no longer be indented. Remove the spaces from a few more lines below this line. When you are through the program should no longer look structured. Now, follow the commands above to reformat the program. How does the program look after you type the commands? What did the commands do?

Go to a specific line number

To go to a specific line number in emacs, simply key esc followed by g, and then key in the line number you wish to go to and hit return.

Key in esc followed by g. At the bottom of the screen in the emacs mini buffer you will see the cursor waiting for you to type in a number. Type in 30. This will move you to line 30 in the program.

Possible solution for "hang-ups"

"Hang-ups" in emacs are times when the emacs text editor is not responding to commands that you are typing. One common solution for many "hang-ups" in emacs is to simply hold down the control key and press g. Note that this does not always work.

Compiling your Pascal program in emacs

To compile your Pascal program in emacs, press esc and then press x. Then type compile and hit return. Emacs will then ask a series of questions before compilation begins. Answer each of these questions. Emacs will then split the screen into two buffer regions, the work area and the compilation area. The compilation area will display information concerning the machines attempt to compile your program.

Let's compile the lab-2.pas and see what it does! To compile the program key in esc followed by x. You should see a M-x in the mini buffer. Type compile and press return. The compile command will be set up to default to the correct buffer line to compile the program you are currently editing. The following line: pc -g -L lab-2.pas is this default compile line. You need to press return to execute the compile command you see in the mini buffer. Emacs will now ask you if you would like to save the file before compiling. Type in y for yes. Look in the compilation buffer to see in compilation results. This may take a few seconds to complete. When you see Compilation finished ... you have compiled your first pascal program.

Saving your work

To save your work in emacs, simply hold down the control key and press x followed by s

Exiting emacs

To exit emacs, simply hold down the control key and press x followed by c

We are finished with emacs so let's exit it. Follow the instructions above to quit the emacs editor.

Special Note

Many of the commands that we have discussed here are easily avialable from the menu at the top of the screen. Use of the mouse and the menus together will result in special commands being executed.