On Wed, May 31, 2017 at 12:02 AM, Eric S. Johansson <[email protected]> wrote:
> Okay started writing my first speech programming command for Leo. > Excellent. > My intent is to look at the text on the line where the cursor is. Take the > line, everything from the first nonwhite space character in the line to the > last nonwhite space character in the line is used as the section heading. > ... > I'm not even close to having this even outlined but here is what I've > pieced together from reading the docs. > Docs are fine, but it's often better to look at real code. In this case, take a look at the code in: leoPy.leo#c.extract... These do pretty much exactly what you want. They should be a pretty reliable guide, and the code shows how to make the code undoable. > new_node = p.insertAsLastChild().copy() ... > why did the example put a copy after insertAtLastChild? There is *never* any need for a copy, because insertAsLastChild always returns a new position. It's a fine point worth knowing. Otoh, the p.moveTo* methods never copy positions, so, depending on circumstance, p.copy() may be required. Searching LeoDocs.leo, I found the example. I didn't write it, but I can see why the author may have thought the copy was necessary. The code immediately *saves* the new position. However, p never changes (even though the code is recursive), so the copy is not needed. > I'm also not sure how to invoke getBodyLines() Exactly as you did. See c.extract. > It gives me: TypeError: must be str, not type -------------------- line 3: last = c.lastTopLevel() * line 4: head, lines, tail, oldSel, oldYview = c.getBodyLines() My guess is that c isn't what you think it is. For real mysteries, you should learn to use g.pdb(). Assuming you are running Leo from a console, which you should *always* do when writing scripts, g.pdb() will drop you into the python debugger, pdb. When that happens, type 'n' to get to the next line. It's necessary because g.pdb() adds an extra call. Now you can do, for example, "p c" to see what c is. I won't go into more details here. You have to learn to use pdb yourself. Any time you spent will pay off big time. Of course, if all you want to do is see what c is, you can do g.trace(c). > I've been staring at this too much for it to make sense anymore. You did right by asking for help. 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.
