PowerAda Getting Started With XEmacs
XEmacs is a public domain X Window-based text editor based on GNU Emacs. Unlike many editors, it is extremely flexible and easily customized. For instance, it may be customized to make Ada programming easier. This short tutorial will give you an idea of XEmacs' Ada features, and will provide some essential Emacs basics. Note that most of these Ada features come from
ada-mode, which is a public domain emacs package written by a number of Team Ada/NYU folks; kudos to them for great work.
We will be using powerada to build a small demonstration program and XEmacs to correct some errors in the source code. The program is a multitasking implementation of the Sieve of Eratosthenes.
This demo will take about 15 minutes to complete.
You should have already created the temporary demo directory and working project. If you have not, please refer to "Required Setup" in the "Introduction" section.
Start powerada in the temporary demo directory with the following command:
In a few seconds, you should see the powerada Navigator window. If the window does not appear, see "Basic Troubleshooting". The powerada Navigator will display the contents of the project root directory.
Building the Program
You will be working with the Sieve of Eratosthenes program which is located in the
=/sieve directory. Navigate to that directory, and you should see this:
Again, there are no files in the working project, but the files in the baseline project are visible ("shadowed") in the display. For more on the powerada Navigator, see "Navigating" in Chapter 4.
To build this program:
Select sieve from the list of files.
Under the Build menu, click Bind Main...
In the Bind File window that comes up, click the Bind button at the lower left.
The Build Manager will load the files and start compiling the units needed to bind the program. For more information, see "Powerada Build Windows" in Chapter 4.
Unfortunately, there are some errors in the source code (due to some sticky keys). The Build Manager stops the job and informs you of the errors with the Edit Compile Errors dialog:
Click the Edit button to edit the errors. Because the source file
windows.body. ada, exists only in the baseline, powerada will prompt you with a dialog to select how you want to edit the file:
On most projects you would usually extract or checkout the source from the CM system, but for demonstration purposes you can just choose Copy from Baseline and Edit to get a local, writable copy of the file. When you click OK, powerada will start XEmacs with the local copy of
The source file is displayed in the top pane. Notice that XEmacs has "fontified" the Ada code, highlighting Ada keywords in bold blue, subprogram and package names in bold red, string literals in purple, and comments in italicized green. (If this much color is too much for you, don't worry--everything can be customized.)
Fixing the Errors
XEmacs displays a list of all the compilation errors in the bottom pane and has positioned the cursor at the first error in the file. (You may have moved from this position with your experiments above, so scroll to line 21.) Change
row to fix this error. You can move to the next error automatically by choosing Next Error in the Ada menu. Here you must change
put. Use Next Error to move to the last error and change
last. Save the changes to the file by clicking the Save button.
XEmacs provides many convenience functions in
ada-mode. Look in the Functions menu. This lists all the subprogram bodies in the current file. Selecting any one of these will bring you right to that subprogram's body.
The Ada menu provides most of the Ada-specific features. For instance, highlight a section of code by left-dragging the mouse over the text, then choose Adjust Case Region from the Ada menu. The case will be converted to LRM-style casing (this can also be easily customized).
Highlight all of the procedure Put and choose Indent Lines In Region from the Ada menu and watch what happens. Ada-mode will automatically indent and adjust the case of new code as you type it, without you ever touching the Shift or Tab key.
Finally, try deleting a semicolon from the source. Choose Syntax Check from the Ada menu. The cursor will be placed near the error so you can fix it and try again.
Now that the errors have been fixed, you must restart the build job. Return to the Build Manager window and click the Continue button. The Build Manager will re-load the file and continue with the compilations then bind the main subprogram to create an executable. Click the Dismiss button to close the Build Manager window. Click the Refresh button in the powerada Navigator window to update the display to contain the newly created sieve executable. Notice that the executable and the changed source file,
windows.body.ada, are displayed in a bold font which indicates that they are local files in the working project.
Now you can run the program to test it. Select the
sieve executable with a left-click, then choose Run Program from the Directory menu. Powerada will open a shell window and run the program there:
Browsing from XEmacs
The Definition Of browsing function is available from XEmacs for compiled units. Within XEmacs, place the cursor on the identifier
row on line 21 of the source file
windows.body.ada. Choose Definition Of from the Ada menu. XEmacs will highlight the parameter declaration for
row. Definition Of is by far the most useful of the browser functions. In general, it will take you to an element's declaration--but not always. Definition Of is intended to be a less formal (but more generally helpful) concept than "Declaration Of".
If you simply want to direct powerada to the file you're editing, for example so you can do a CM or Build operation on it, choose Send to PowerAda from the Ada menu. This will open a new powerada window with a Text View of the file, at the same position. This is often more effective when the source file has changed significantly, because from the powerada Text View you can Visit to the most recently compiled view.
That's the end of the demo. You can now exit powerada by choosing Quit from the powerada File menu and Exit XEmacs from the XEmacs File menu.