Is there any (easy) way for an @rclick script to know its own headline?

21 views
Skip to first unread message

Jacob Peck

unread,
Apr 14, 2021, 12:14:40 PM4/14/21
to Leo-editor Group
Hi all,

I've been toying around with a few things lately, and I've hit a situation where I want several @rclick nodes to do something very similar -- something that can be keyed off of their headlines.  That way I could just copy and paste the nodes and change the headlines and everything would hopefully just work.

basically, the code in each @rclick would be something like:

@rclick foo
---
value = myHeadline[8:]
do_the_thing(value)
---

Which would end up calling do_the_thing('foo').  But I'm stuck on how to get myHeadline -- 'p' is of course the position of the currently selected node, not the @rclick itself.  Is there some API to grab the position (or vnode?) of the executing script?

It's no big deal if this isn't possible, but it would be really convenient if it were.  I've poked around the source and haven't found what I'm looking for, but maybe I'm not looking in the right places.

Thanks for any pointers!
Jake

Edward K. Ream

unread,
Apr 14, 2021, 7:10:36 PM4/14/21
to leo-editor
On Wed, Apr 14, 2021 at 11:14 AM Jacob Peck <gates...@gmail.com> wrote:

> I'm stuck on how to get myHeadline -- 'p' is of course the position of the currently selected node, not the @rclick itself.  Is there some API to grab the position (or vnode?) of the executing script?

Yes. It's a bit of an Easter Egg, but it is documented.

@rclick print-hi @args=print-hi

g.cls()
print('rclick hi: %s' % c.p.h)
print('dir()', dir())
print(script_args)
print(script_gnx)

prints:

rclick hi: @rclick say-hi @args=say hi
dir() ['__builtins__', '__name__', 'c', 'g', 'input', 'p', 'script_args', 'script_gnx']
['say hi']
ekr.20210414174148.1


The calling tree is:

sc.handleAtRclickNode (handles @rclick)
sc.getArgs  (handles @args)
sc.registerAllCommands
c.executeScript
c.executeScriptHelper (injects script_args and script_gnx)

HTH.

Edward
Reply all
Reply to author
Forward
0 new messages