On Sat, Dec 3, 2016 at 9:51 AM, djc <[email protected]> wrote:
> I would like to create an outline with several levels with a python script.
>
[snip]
>
> but I can find not find an example or documentation of how to promote or
> demote the outline level at the current position
> .
>
There are several possible approaches to finding code in Leo. All are
appropriate in one way or another.
1. Search.
Just now, I knew that the command I wanted started with moveOutline. I
searched for that in leoPy.leo and found c.moveOutlineDown, in the node
Code-->Core classes-->@file leoCommands.py-->class Commands-->c.Command
handlers-->Outline menu (commands)-->Move... (Commands)
So, to do what you want, your script could do:
c.moveOutlineRight(), assuming that the node to be moved is selected. If
it isn't, c.selectPosition(p) will select it.
*Important*: the commander methods (c methods) are high-level commands.
They do the complete command, including redraw.
Many times there are corresponding position methods (p methods). These are
lower level and do not do a redraw. That's often what you do want when
doing more complex operations.
2. Use typing completion.
Typing <Alt-x> move-<tab> will show you lots of move commands, including
move-outline-right. You can execute any command by name this way:
c.k.simulateCommand("command-name"),
in this case,
c.k.simulateCommand('move-outline-right')
This will do the redraw automatically, because it invokes
c.moveOutlineRight().
Leo's scripting tutorial <http://leoeditor.com/tutorial-scripting.html>
doesn't cover these basic things. It probably should. Neither does Leo's cheat
sheet <http://leoeditor.com/cheatsheet.html>, but the section called Moving
Outline Nodes <http://leoeditor.com/cheatsheet.html#moving-outline-nodes>
does tell you the *names* of the commands to do move outline nodes. This
is a hint, which you can use in c.k.simulateCommand ;-)
3. Search for the command name in Leo. Python decorators define all of
Leo's commands, so search for 'move-outline-down' in leoPy.leo will,
eventually get you to c.moveOutlineDown, just as in point 1 above. The
quick way to search is to use the cff command ;-)
HTH. Besides these little tricks, it would probably be a good idea to
spend 10 or 15 minutes just looking through leoPy.leo. Pay particular
attention to the files, and glance at the classes the files contain. You
shouldn't try to remember much. You just want to get a feel for the shape
of Leo's code.
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 https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.