Yes ... 'many' of the scripts I come across, eg. on this newsgroup, need a 
bit of tweaking to run with more modern Leo. But I think a collection with 
some of the concepts 'curated' and commented on would be useful.

Like you, I always forget about scripts.leo; not sure that is the right 
place.

On Monday, January 2, 2023 at 11:47:36 PM UTC [email protected] wrote:

> Theoretically they can go into scripts.leo, but I always forget about that 
> outline and a lot of its scripts are so long unmaintained that they don't 
> even work.  That, or they are so specialized that it's hard to even know 
> what they do.
>
> I do agree that a collection of small utility scripts would be great for 
> people trying to learn how to program for Leo - IF they are well 
> documented, and clear and simple.
>
> On Monday, January 2, 2023 at 6:17:38 PM UTC-5 jkn wrote:
>
>> It would be good to have a miscellany of little script examples like this 
>> easily
>> available, to give people assistance with learning Leo scripting. I know
>> a few have been published as Github gists in the past, and there are some 
>> clues
>> in the Leoeditor.com documentation, but a few dozen snippets on one place,
>> with some annotation, would be very useful, I think. I might even have a 
>> couple
>> of my own to contribute...
>>
>> J^n
>>
>>
>> On Monday, January 2, 2023 at 5:14:47 AM UTC [email protected] wrote:
>>
>>> Leo has commands to capitalize, upcase, and lowercase the body text or 
>>> selections of the body text.  I could not find a command to convert to 
>>> title case (first letter of every word capitalized).  So here is a script 
>>> to do so.
>>>
>>> The script does not take into account any tricky edge cases - it just 
>>> uses the Python string.title() method.  The command is undoable.
>>>
>>> """Convert selection or body to title case."""
>>> w = c.frame.body.wrapper
>>> p = c.p
>>> s = p.b
>>> u = c.undoer
>>>
>>> start, end = w.getSelectionRange()
>>> use_entire = start == end  # no selection, convert entire body
>>>
>>> undoType = 'title-case-body-selection'
>>> undoData = u.beforeChangeNodeContents(p)
>>>
>>> if use_entire:
>>>     p.b = s.title()
>>> else:
>>>     sel = s[start:end]
>>>     head, tail = s[:start], s[end:]
>>>     p.b = head + sel.title() + tail
>>>
>>> c.setChanged()
>>> p.setDirty()
>>> u.afterChangeNodeContents(p, undoType, undoData)
>>> c.redraw()
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/2a32918b-0a05-4693-8a25-8d465d8b6769n%40googlegroups.com.

Reply via email to