Thanks for the comments!
*> This demo works as advertised in the felix-fix-script-results
branch. The whole-process button will loop indefinitely in devel, **....*
oh yeah, haha! -> Try with the* felix-fix-script-results*
branch, otherwise the whole-process button will loop !
*> Let's merge this PR soon.*
I agree.
Félix
On Sunday, April 20, 2025 at 3:55:56 PM UTC-4 jkn wrote:
> I like the sound of this! I will take a look, thanks for your work here,
> Felix.
>
> J^n
>
> On Sunday, April 20, 2025 at 1:15:51 PM UTC+1 Edward K. Ream wrote:
>
>> On Saturday, April 19, 2025 at 7:40:39 PM UTC-5 Félix wrote:
>>
>>
>> I've made two small but useful improvements which you can preview in the
>> branch 'felix-fix-script-results'.
>>
>>
>> Thanks for this work. My short response: the PR is useful and sound. More
>> details below.
>>
>>
>> *1- Return values from commands*
>>
>> Until now, calling a command with
>> doCommandByName, executeMinibufferCommand or doCommand didn’t return the
>> result of the underlying method. (c.keyHandler.funcReturn was removed a
>> while ago) That’s now fixed — these functions will return whatever the
>> command’s method returns.
>>
>> For example, the convert-blanks command (which replaces leading spaces
>> with tabs) returns True if it made any changes, and False otherwise.
>> Previously, calling it with *c.doCommandByName('convert-blanks')* would
>> return None, but now it correctly returns the boolean result — just like
>> calling *c.convertBlanks()* directly.
>>
>>
>> This feature eliminates a confusing difference between various parts of
>> Leo's API. I fully approve this change.
>>
>> The diffs for * c.executeScriptHelper* do not reveal a subtle detail.
>> Happily, this detail will cause no problem.
>>
>> The detail: *c.executeScript* and *c.executeScriptHelper* take a *namespace
>> *kwarg. What happens if namespace (a dict) contains a "result" key?
>> Happily, the answer is, nothing. The local *d* var (another dict) does
>> not contain a "result" key, so the lines:
>>
>> if namespace:
>> d.update(namespace)
>>
>> will not affect the namespace kwarg. Therefore, the PR will not affect
>> the exec statement in any way.
>>
>> Note: I do not believe this analysis needs to be part of the new
>> documentation ;-) You might mention it in the PR itself.
>>
>> *2 - Another feature for user-defined scripts*
>>
>> I've also added a way for user-defined scripts (those inside @command or
>> @button nodes) to return values as well. Since top-level return statements
>> aren't allowed in scripts executed with exec, you can now define a global
>> variable named result, and Leo will return its value after the script runs.
>> For example:
>>
>> global result
>> result = 42
>>
>>
>> The analysis above shows that "polluting" the namespace of the exec
>> statement will *never* cause any problem.
>>
>> *I've attached a small Leo file demonstrating a use case for this.*
>>
>>
>> This demo works as advertised in the felix-fix-script-results branch. The
>> whole-process button will loop indefinitely in devel, but that's not a real
>> problem ;-)
>>
>> Let's merge this PR soon.
>>
>> 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 view this discussion visit
https://groups.google.com/d/msgid/leo-editor/3b88b225-b2f9-4917-813d-d943a460000en%40googlegroups.com.