I'll check out that Freewin plugin, thank you. I'm not sure how to actually execute the functions, even if i've found the definition. Recently I made this (which is obviously very ugly for multiple reasons) - for a duplicate-line command. I started with your example, Tom, then added/modified the built-in command for `extend-to-line` (which has a bug if on the last character of the line, but i haven't had time to look at that yet). I wasn't sure how to call these without rewriting them from scratch.
``` @language python # duplicate-line copies the selected line in the body pane # and preserves the insertion point on the new line as well # todo: incorrect if at last character in line w = c.frame.body.wrapper #wrapper p = c.p #position s = p.b #string of body u = c.undoer #undo orig_ip = w.getInsertPoint() max_chars = len(s) start = orig_ip while 0 <= start < max_chars and not s[start] == '\n': start -= 1 start += 1 end = orig_ip while 0 <= end < max_chars and not s[end] == '\n': end += 1 line_text = s[start:end] new_line_text = '\n' + line_text column_offset = max(0, orig_ip - start) new_ip_offset = len(new_line_text) new_ip = orig_ip + new_ip_offset head, tail = s[:end], s[end:] undoType = 'duplicate-line' undoData = u.beforeChangeNodeContents(p) p.b = head + new_line_text + tail w.setInsertPoint(new_ip) c.setChanged() p.setDirty() u.afterChangeNodeContents(p, undoType, undoData) c.redraw() # g.es('---') ``` On Tuesday, January 10, 2023 at 5:30:56 PM UTC-5 tbp1...@gmail.com wrote: > Yes, it can be hard to find out how to do things you want in Leo. The > good news is that you can do most anything. Remember to undo/redo > operations that change a node or the tree - my title-case script shows how > to do that for node content. > > Leo's code base is in the PyLeoRef.leo outline, as I imagine you already > know. IMHO, the best way to find code that might be related to what you > want is the Nav tab, along with tab completion of minibuffer commands. > When you type (or paste) into the search box in the Nav tab, it shows you > node headlines that match. After you hit ENTER, it also shows you body > matches. > > For example, you write that you want to duplicate a line. So you have to > select or at least find a line to copy. I remembered that there is a > command to move a line up. I typed "move" into the minibuffer and then TAB > to get a list of all matching command. There it was - "move-lines-up". I > copied that and pasted it into the search box in the Nav tab. This showed > a match for "@cmd('move-lines-up')". Clicking on that took me to where the > command is defined. Right there it shows how to get the selection range, > and how to get the line from the selection. > > The other excellent feature is the ability to CTRL-click on a function or > method call and (usually) get taken to its definition. > > Forgive me if you already know these things. They have been really helpful > for me. And, as Edward would advise, judicious use of clones can be very > helpful. Also, you might want to check out the Freewin plugin - it opens a > stand-alone window that shows a single node in a basic editor, which you > can keep open alongside Leo's window for reference while you navigate to > some other node. That's probably new since you were last working with Leo. > > On Tuesday, January 10, 2023 at 4:11:17 PM UTC-5 Kevin Henderson wrote: > >> This is great timing Thomas, thank you! >> I've been away from Leo for a while, but making another attempt to get >> back into it. >> >> I've had a _heck_ of time figuring out how to do what showed, in my case >> I wanted a 'duplicate-line' command. >> It really is tremendously difficult to figure out what to do or where to >> start. >> >> a couple of observations: >> - what got me the furthest (but not all the way there) is/was the >> `scripts.leo` file (i.e. the 'Text' section). >> - most of the scripts & guides seem to be around working with nodes >> (which seems easier) rather than body text. >> - the body text seems very challenging/manual to work with, perhaps some >> utility functions would make this easier >> - e.g. for my duplicate line command, i'll have repeat most of Thomas's >> code above, there isn't a simple utility function >> - there are already commands such as 'extend-to-line'/extendToLine, but >> do I have access to these or do i have to reproduce them? >> - it would be nice to group these docs & content by context, e.g. the >> guides with the examples >> >> Anyway, it's good to say hello again, glad to see things are still >> plugging. >> >> Cheers & Happy 2023, >> Kevin >> >> >> On Wednesday, January 4, 2023 at 1:27:17 PM UTC-5 tbp1...@gmail.com >> wrote: >> >>> Let's add the scripting-miscellany link to Leo's Help menu. >>> >>> On Wednesday, January 4, 2023 at 11:32:09 AM UTC-5 Edward K. Ream wrote: >>> >>>> On Wednesday, January 4, 2023 at 10:18:53 AM UTC-6 Edward K. Ream wrote: >>>> >>>> > I've just added this entry >>>> <http://leoeditor.com/scripting-miscellany.html#keeping-clean-files-up-to-date> >>>> >>>> (online and in devel). >>>> >>>> And I've just updated this page >>>> <http://leoeditor.com/directives.html#clean-path> in Leo's Reference >>>> Guide. >>>> >>>> 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 leo-editor+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/bf7dc539-ad46-4eb6-9c55-90d116af752cn%40googlegroups.com.