On Sun, Oct 16, 2011 at 10:46 PM, Largo84 <[email protected]> wrote:

> Maybe I'm missing something here, probably because I've always
> dismissed scripting because I don't have the foggiest notion of how to
> write one.

As you have just discovered, Leo does have scripting docs.

However, let me say a few words about scripting in *this* context.

What makes Leo scripting so important is that the predefined c, g and
p variables give *full* and *easy* access to all the data in your
outlines, as well as hundreds, if not thousands, of useful Python
functions in Leo's core.

You could say that these variables, especially c, define a *very*
easy-to-use DOM (Document Object Model) through which you can get or
set any data in **your** outlines.

The hello world example is::

    for p in c.all_positions():
        indent = '.' * p.level()
        print('%s%s' % (indent,p.h))

Here, c.all_positions() delivers a list of positions, and p.level()
and p.h deliver the indentation level and head string of position p.

Another crucial part of Leo scripting is that you can put Leo script
*anywhere* in a Leo outline.  You can do this in three ways:

1. You can just put the script above in the body of any node and run
it with Ctrl-B (execute-script).

2. You can make a script button by putting the script in an @button node.

3. You can make a new Leo command by putting the script in an @command node.

> I can see the advantages of a 'search' compared to a
> breakable link, but will this require that users will have to learn
> Python programming in order to fully leverage this?

An excellent question.  The answer is, yes and no.  Let me explain.

Answer 1: "No"

The recent Ahas clarify the relationship between linking and scripting.
They create a new *model* for scripting, one in which **scripts create
content.**  I'll say more about this new model in a separate thread.

For now, though, I'll just say that this new model opens up new
possibilities which may result in new kinds of Leo commands.  These
new commands will surely benefit many Leo users, not just those who
feel comfortable writing Leo scripts.

Answer 2: "Yes"

Sophisticated will surely want to write their own scripts: no possible
set of Leo commands could possibly begin to cover all the
possibilities that Leo scripting provides.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to