On Monday, December 9, 2024 at 3:36:37 PM UTC-6 jkn wrote:
I've been meaning to ask this for ever...Is there a way to pass argument(s)
to leo @command-s?
Hi Jon,
Good question. The short answer is "no", but there are workarounds.
I often use bespoke scripts that I customize by hand. For example, here is
a script that I use to import multiple files:
@language python
"""Recursively import all python files in a directory and clean the
result."""
@tabwidth -4 # For a better match.
g.cls()
dir_ = r'<<path to a folder>> # <--- customize as needed
c.recursiveImport(
dir_=dir_,
kind = '@clean', # '@auto', '@clean', '@nosent','@file',
recursive = True,
safe_at_file = True,
theTypes = ['.py',],
verbose = True,
)
if 1:
last = c.lastTopLevel()
last.expand()
if last.hasChildren():
last.firstChild().expand()
c.redraw(last)
print('Done')
I will typically execute this script several times, so it would be *less*
convenient to "generalize" it by asking for a path.
*Other workarounds*
It's almost always simplest to write your own scripts. But if you *really*
want to write a general command, Leo provides ways to do that.
The *big hint*: look for code in Leo's codebase that does something similar
to what you want. For example, Leo's find commands prompt for one or more
arguments. The code isn't pretty. *find.find-next* and *find.change-all*
show how to set up the required state machines.
The node *c.interactive** in leoCommands.py contains helpers that set up
state machines.
*Summary*
Writing bespoke scripts is almost always the simplest solution.
Other solutions involve state machines. I would only consider such
approaches in extraordinary circumstances.
HTH.
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/37e3f520-5f8f-4f00-ab5e-3ff1ba1b6b46n%40googlegroups.com.