## Leo : Basics : What is Leo - Continued

In the first tutorial in this series, we saw the basic outlining and file derivation features of Leo. Let's take a further look at how Leo's derived file functions can be put to use. We will use the creation of a computer program as an example, however, the operations are useful in other situations involving complex text documents.

Author: Joe Orr

A note for programmers: this tutorial, in addition to being an illustration of more file derivation operations, is an introduction to how Leo can facilitate a new kind of Literate Programming . Rather than further clarify what this means now, we'll just show an example. More information about Literate Programming is available in the documentation that comes with Leo. But keep in mind that the problem to be solved by literate programming is to provide an easy-to-understand road map to a complex programming project. Using Leo, you plan your code, explain it, and write it all in the same document. You use English, not a new language like UML, and you can explain and describe all levels of structure in as many ways as you want - not just classes and methods.

Author: Joe Orr

Here we've just opened Leo.

Author: Joe Orr

This website has examples from the highly recommended Java and XML book by Brett McLaughlin. We're going to download the Chapter 6 examples.

Author: Joe Orr

Here we've unzipped the examples, and have selected the folder containing the java files.

Author: Joe Orr

Now back to Leo. We are going to import the java files.

Author: Joe Orr

Here we have navigated to the folder containing the java files, and will select the first Java file.

Author: Joe Orr

Leo has imported the file.

The @file directive shown in the highlighted headline is similar to the @root directive shown in the first tutorial. The @file directive is explained in greater detail later in this tutorial.

The @language directive indicates that Java syntax highlighting will be used. The @others directive indicates that all unnamed sections will be derived. An unnamed section is a node defined without angle brackets.

Author: Joe Orr

By expanding the nodes, you can see that Leo has automatically put each class and method in a separate node when importing the Java file.

Author: Joe Orr

Here we have imported the other two Java files.

Author: Joe Orr

Let's suppose we're interested in working on the UpdateItemServlet.java class.

1. Select the doPost method.
2. The body of the method appears in the text pane.

Leo has automatically broken down the program by method. But there are still 200 lines of code in the doPost node.

Author: Joe Orr

Let's break the doPost method down further. First we type in a new section / node name.

Author: Joe Orr

Now we select all of the code (text - light grey) we want to go into our new section.

Author: Joe Orr

We then choose Edit - Edit Body - Extract Section.

Author: Joe Orr

You can see that

1. The new node has been added.
2. The selected code has been extracted from the current section, leaving only the section indicator.

Author: Joe Orr

And when we select the new node in the outline window, we can see that the code has been pasted into our new section as expected.

Author: Joe Orr

In this way, you can continue to break down the program, making it much easier to focus on areas that you want to work on or study. You can add more files - in addition to adding the java files, you can add all of the xml, htm, wsd, and other files that come with this particular project. Of course, you can also add new nodes and text, as shown in the first tutorial.

But not only can you break the program down into smaller parts, you can also regroup parts of the program into different views. You can make a new branch in the outline that rearranges existing parts of the outline in a different way. To see this feature in action, read the Outlines tutorial of this tutorial series, or view some of the tutorials in the Examples section of this tutorial series.

Author: Joe Orr

A couple more notes about the @file directive: in contrast to the @root directive we saw in the first tutorial, there is no need to untangle or tangle if you use this directive. This is because in this case Leo embeds all of the outline information in the derived file, and then in effecttangles or untangles from the derived file whenever the .leo file is opened or saved.

Let's examine this more closely. First, save the file.

Author: Joe Orr

We've saved the file as "sample.leo" in the same folder as the java files.

Author: Joe Orr

We've

1. selected our new node again, and
2. added a line of code.

Author: Joe Orr

We hit [CTRL-S] to save, and the changes are written to UpdateServlet.java .

Author: Joe Orr

Now we close Leo, and look at the folder with our java files in Windows Explorer. We'll open the UpdateItemServlet.java file with a text editor.

Author: Joe Orr

Looking at UpdateItemServlet.java in a text editor, we can see that Leo has updated the file to contain

1. Outline information embedded as a java comment.
2. Our code change.

Author: Joe Orr

Now let's add some code using the text editor.

Author: Joe Orr

We save the text file, then open the our Leo outline again.

Leo opens right back to where we were, and we can see that the code we added has been read into our outline.

This means that you can transparently switch back and forth between Leo and the editor or programming tool of your choice, and each time Leo will remember your outline.

Author: Joe Orr

This concludes the basic introduction to Leo, but to actually use it you'll need to know a little more. You'll need to learn how to make an outline, and perhaps a little more about derived files. It should take about fifteen minutes to learn most of the operations you need to be proficient. But first, read on to the next tutorial, where you can learn how to install Leo.

Author: Joe Orr

Created with ScreenBook Maker Last update: 8/12/2002 Additional Trademark and Copyright Information