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.
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.
Here we've just opened Leo.
This website has examples from the highly recommended Java and XML book by Brett McLaughlin. We're going to download the Chapter 6 examples.
Here we've unzipped the examples, and have selected the folder containing the java files.
Now back to Leo. We are going to import the java files.
Here we have navigated to the folder containing the java files, and will select the first Java file.
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.
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.
Here we have imported the other two Java files.
Let's suppose we're interested in working on the UpdateItemServlet.java class.
Leo has automatically broken down the program by method. But there are still 200 lines of code in the doPost node.
Let's break the doPost method down further. First we type in a new section / node name.
Now we select all of the code (text - light grey) we want to go into our new section.
We then choose Edit - Edit Body - Extract Section.
You can see that
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.
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.
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.
We've saved the file as "sample.leo" in the same folder as the java files.
We've
We hit [CTRL-S] to save, and the changes are written to UpdateServlet.java .
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.
Looking at UpdateItemServlet.java in a text editor, we can see that Leo has updated the file to contain
Now let's add some code using the text editor.
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.
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.