Below is the first draft of an "introductory example", supposedly to start
off the scripting chapter.
This is *way* too much data! Newbies will run away screaming. Somehow, it
must be greatly simplified.
Before writing this example, I had *no idea* how much lies beneath the
surface of simple Leo scripts...
QQQQQ
Leo scripts are elegant--they pack a lot of power in small packages. For
example, this short script prints the headline of all nodes in the outline
in Leo's log pane, in outline order::
for p in c.all_positions():
g.es(p.h)
These two lines illustrate *all* the basic features of Leo scripts:
predefined symbols, generators, positions and vnodes:
- The execute-script command runs this script without errors because the
execute-script command predefines c and g.
- c is a Commands object; g is the leo.core.leoGlobals module. c and g give
access to all of Leo's source code, including everything commonly used in
Leo scripts.
- c.all_positions() is a **Leo generator**, a `Python generator`_ defined
by Leo.
- Leo generators **traverse** (visit each node of) the outline, usually in
outline order.
- Leo generators yield a sequence of **positions** p.
- Each position represents a particular state (position) of the traversal.
- For any position p, p.v is the **vnode** at p.
- vnodes contain *all* the data in Leo outline nodes.
- For any vnode v, v.h is the node's headline; v.b is the node's body text.
(p.b and p.h are synonyms for p.v.b and p.v.h).
- The g.es function prints its arguments to the Log pane.
Whew! There is a lot to digest in this simple example!
Happily, scripting Leo soon becomes second nature.
The following sections explain all the terms discusses here in detail.
QQQQQ
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.