@rst current file name

37 views
Skip to first unread message

frakel12

unread,
Sep 30, 2018, 5:44:45 PM9/30/18
to leo-editor
Hallo, 

is there a way to find out the name of the current intermediate file Leo is producing when invoking a @button script with c.k.simulateCommand('rst3') from any sub-node of an @rst node.

In other words, how can I figure out the name of 'mydocument.tex' when compiling the node '@rst mydocument.tex' ??

Thank you so much!
--franz

Edward K. Ream

unread,
Oct 1, 2018, 6:11:40 AM10/1/18
to leo-editor
On Sunday, September 30, 2018 at 4:44:45 PM UTC-5, frakel12 wrote:

> is there a way to find out the name of the current intermediate file Leo is producing when invoking a @button script with c.k.simulateCommand('rst3') from any sub-node of an @rst node.

The rst3 command may produce multiple results, so there is no unique answer.

> In other words, how can I figure out the name of 'mydocument.tex' when compiling the node '@rst mydocument.tex' ??

I presume you are talking about the full path to mydocument.tex, but I'm not sure I understand your question.

Let's look at the code.  The top-level code is rst.rst3 command & helpers, in leoRst.py.  To find all @rst nodes, rst.processTopTree uses:

roots = g.findRootsWithPredicate(self.c, p, predicate=predicate)

For each root node in the roots list, rst.processTopTree calls:

self.root = p.copy()
self.processTree(p, ext=None, toString=False, justOneFile=justOneFile)

So, within the rst code itself, self.root is the root @rst node.  The calculation of the output path occurs deep in the called code.  You could try to find and use that code, but that won't be pretty.

Instead, your script could use g.findRootsWithPredicate (with a simpler predicate) to compute it's own list of @rst nodes, and call rst.processTree for each root.  That way you would be sure what @rst node is being processed, which in turn makes the path calculations easier.

HTH.

Edward

Franz Kelnreiter

unread,
Oct 1, 2018, 11:15:26 AM10/1/18
to leo-e...@googlegroups.com
     Thank you Edward I guess it must be a simpler solution. Let me explain
      once again.      
      I have for example the following structure:

            |-@rst myplan.tex
              |- myplan-node1
                    |- myplan-node2
            |-@rst mylist.tex
              |- mylist-node1
                    |- mylist-node2

      if I call `rst3` on the `mylist-node2` node Leo compiles a
      `mylist.tex.rst` file. I am generally not interested in the full path
      but only in the file name which always changes according to the node I
      am in. This name is located in `v.h` in one if `p.self_and_parents()` nodes.

      Apparently it is stored in the root property of RstCommands-class
      as you pointed out.

      But how can I access `RstCommands.root.h` in a @btn script? 

      When I do a g.es_print(p.h) I only get the headline of the current
      node whereas I need the head of the current rst root node...

     Sorry, I don't quite get it.

Thank you.
-franz

     

Edward K. Ream

unread,
Oct 1, 2018, 5:51:42 PM10/1/18
to leo-editor
On Mon, Oct 1, 2018 at 10:15 AM Franz Kelnreiter <kelnr...@gmail.com> wrote:

But how can I access `RstCommands.root.h` in a @btn script? 

All scripts work the same, including @button scripts and @command scripts.

Given a node p: p.isAnyAtFileNode() returns True if p is an @file, @auto, @clean, etc node.

In that case, p.anyAtFileNodeName() is the contents actual file name in the headline.

But that doesn't resolve the actual path.  g.fullPath(c, p) does that, taking account of @path directives and also default settings.  See the actual definition of g.fullPath for details.

HTH.

Edward

Franz Kelnreiter

unread,
Oct 2, 2018, 3:17:45 AM10/2/18
to leo-e...@googlegroups.com
Thank you Edward. I finally figured out what I wanted :)
My solution is:

.. code::

  for n in p.self_and_parents():
    if n.h.startswith("@rst "):
        rstfn = n.h.strip()[5:]
        g.es("file to process: %s" % rstfn)

This always returns the file name of the currently active rst - root node.

--franz

Edward K. Ream

unread,
Oct 2, 2018, 10:58:11 AM10/2/18
to leo-editor
On Tue, Oct 2, 2018 at 2:17 AM Franz Kelnreiter <kelnr...@gmail.com> wrote:

Thank you Edward. I finally figured out what I wanted :)

Glad to hear it.  Happy scripting.

Edward
Reply all
Reply to author
Forward
0 new messages