Leo : Basics    What is Leo - Continued  

Page 1


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.





Page 2


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.





Page 3


Here we've just opened Leo.

  Click on the image for page view.




Page 4


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

  Click on the image for page view.




Page 5


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

  Click on the image for page view.




Page 6


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

  Click on the image for page view.




Page 7


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

  Click on the image for page view.




Page 8


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.

  Click on the image for page view.




Page 9


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.

  Click on the image for page view.




Page 10


Here we have imported the other two Java files.

  Click on the image for page view.




Page 11


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.

  Click on the image for page view.




Page 12


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

  Click on the image for page view.




Page 13


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

  Click on the image for page view.




Page 14


We then choose Edit - Edit Body - Extract Section

  Click on the image for page view.




Page 15


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.
  Click on the image for page view.




Page 16


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.

  Click on the image for page view.




Page 17


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.





Page 18


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.

  Click on the image for page view.




Page 19


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

  Click on the image for page view.




Page 20


We've

  1. selected our new node again, and
  2. added a line of code.
  Click on the image for page view.




Page 21


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

  Click on the image for page view.




Page 22


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.

  Click on the image for page view.




Page 23


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.
  Click on the image for page view.




Page 24


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

  Click on the image for page view.




Page 25


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.

  Click on the image for page view.




Page 26


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.




Text Author: Joe Orr   Creative Commons - Non Commercial - Share Alike  
Created with Screenbook Maker   Additional Trademark and Copyright Information