Macros in Leo 5

147 views
Skip to first unread message

bobS

unread,
Dec 2, 2014, 6:43:58 PM12/2/14
to leo-e...@googlegroups.com
Test Parameterized Nodes
A
   body text: << meow ( purrrrr, zzooooot ) >>
B
   body text: << meow ( spit, necessary ) >>
Parameterized Nodes
   << Meow >>
      body text: I mmmm sooo happy I could << 1$ >>.
                     But I don't know if I have all the << 2$ >>
                     money.

When I click on Parameterize Section Reference in the Outline menu, I get:

exception executing command

Traceback (most recent call last):

  File "/home/rshanley/Leo5.0-final/leo/core/leoCommands.py", line 556, in doCommand
    val = command(event)

  File "/home/rshanley/Leo5.0-final/leo/plugins/macros.py", line 111, in parameterize
    sr = s = body.getAllText()

AttributeError: 'LeoQtBody' object has no attribute 'getAllText'


PyQt4 is installed.

bobS

unread,
Dec 3, 2014, 2:21:22 PM12/3/14
to leo-e...@googlegroups.com
Attached is MacroTest.leo, which produced the following under Leo 4.11a1, build 5020 running on (uname -a) Linux bob-VirtualBox 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux.

This output occurred when the node Parameterized Nodes was selected and Parameterized Section Reference clicked under the Outline menu.

Leo Log Window
Leo 4.11a1, build 5020, 2012-02-26 13:18:08 -0600
Python 2.7.3, qt version 4.8.1
linux2
reading: /home/rshanley/h/MacroTest.leoreading settings in /home/rshanley/Leo-4.11-a2/leo/plugins/leoPluginsRef.leo

reading settings in /home/rshanley/Leo-4.11-a2/leo/plugins/leoPluginsRef.leoparameterize <_sre.SRE_Pattern object at 0x3f7e2e0>
parameterize no match u''

save-file-as: Wed Dec  3 13:13:11 2014wrote recent file: /home/rshanley/.leo/.leoRecentFiles.txt

saved: MacroTest.leo

For Leo 5, the same steps described above produced the behavior described in the initial post.
MacroTest.leo

Edward K. Ream

unread,
Dec 3, 2014, 3:27:18 PM12/3/14
to leo-editor

​Thanks for this report.  I did not write the macro.py plugin, but I'll see what I can do...

Edward

Edward K. Ream

unread,
Dec 3, 2014, 4:33:15 PM12/3/14
to leo-editor
On Wed, Dec 3, 2014 at 2:27 PM, Edward K. Ream <edre...@gmail.com> wrote:


On Tue, Dec 2, 2014 at 5:43 PM, bobS <rjsha...@gmail.com> wrote:

When I click on Parameterize Section Reference in the Outline menu, I get:

exception executing command

Traceback (most recent call last):

  File "/home/rshanley/Leo5.0-final/leo/core/leoCommands.py", line 556, in doCommand
    val = command(event)

  File "/home/rshanley/Leo5.0-final/leo/plugins/macros.py", line 111, in parameterize
    sr = s = body.getAllText()

AttributeError: 'LeoQtBody' object has no attribute 'getAllText'


PyQt4 is installed.


Rev 311ca64 probably fixes this error, a relatively recent bug.  I haven't done any real testing.  Please report any further problems.

Edward

bobS

unread,
Dec 11, 2014, 2:52:56 PM12/11/14
to leo-e...@googlegroups.com
From the docstring for plugin macros.py, it seems as though the content of the A node is changed into the body text for << Meow >> with the arguments in A's << meow ( purrr, zzooooot ) >> as body text in sub-nodes of A. So A's body would be changed to look the same as the << Meow >> body, with sections << 1$ >> and << 2$ >> as sub-nodes below it. The cursor must be placed where the x appears in the following line from A's body:
<< meow ( purrr, zzzooooot ) >>x
before "Parameterize Section Reference" is selected in the Outline menu. I've messed with capitalization of the M in Meow,etc. Any help would be appreciated.

Would someone who has made this work please explain how they did it? I have probably misunderstood the docstring.

On Tuesday, December 2, 2014 5:43:58 PM UTC-6, bobS wrote:

bobS

unread,
Dec 12, 2014, 10:52:59 AM12/12/14
to leo-e...@googlegroups.com
Modifying the macros.py and printing out stuff with g.es shows that the regular expression used to parse the text in the A & B nodes does not expect any embedded blanks. The examples in the docstring all have embedded blanks which cause the regular expression parse to fail. So A should have <<meow(purrrrr,zzooooot)>> with no blanks and the parse will succeed. But two things are still missing from the result: A is not altered to contain the body text from the << Meow >> node and only one sub-node, <<2$>>, gets created instead of two (<<2$>> and <<1$>>). The <<2$>> node does have the correct content: zzooooot. In addition, when the cursor is placed at the end of the <<meow(purrrrr,zzooooot)>> data in the A node and Parameterize Scection Referece is selected from the Outline node, The <<$2>> node is given two empty sub-nodes. Finally, when meow is given three arguments, a <<3$>> node gets created, instead of <<2$>> with the correct content along with three empty sub-nodes.

bobS

unread,
Dec 13, 2014, 12:23:24 AM12/13/14
to leo-e...@googlegroups.com
The attached version of macros.py makes the changes to the outline that seem to be what was intended. But I didn't write this plugin, either. All the debug code has been left in -- a lot of printing to the log pane.


On Tuesday, December 2, 2014 5:43:58 PM UTC-6, bobS wrote:
macros.py

Edward K. Ream

unread,
Dec 13, 2014, 7:19:57 AM12/13/14
to leo-editor
On Fri, Dec 12, 2014 at 11:23 PM, bobS <rjsha...@gmail.com> wrote:
The attached version of macros.py makes the changes to the outline that seem to be what was intended. But I didn't write this plugin, either. All the debug code has been left in -- a lot of printing to the log pane.

​Thanks for this.  I'll up it with minor changes:

- Credit to you in the version history.

- Enable the debugging code in the usual way, with per-method debug flags, and convert g.es to g.trace.

- Restore the r''' docstring.  It  was there to prevent a pylint warning.

After making these changes I'll ask for other testers.

Edward

Edward K. Ream

unread,
Dec 13, 2014, 8:52:17 AM12/13/14
to leo-editor
On Sat, Dec 13, 2014 at 6:19 AM, Edward K. Ream <edre...@gmail.com> wrote:
On Fri, Dec 12, 2014 at 11:23 PM, bobS <rjsha...@gmail.com> wrote:
The attached version of macros.py makes the changes to the outline that seem to be what was intended. But I didn't write this plugin, either. All the debug code has been left in -- a lot of printing to the log pane.

​Thanks for this.  I'll up it with minor changes:

​Rev f6e3f7e contains substantial revisions, leading to version 2.0.
 
​1. ​
I have rewritten
​all the code to bring it up to modern Leonine coding practices, to simplify unnecessarily complicated code, and to improve traces.

​2. I rewrote the findParameters method.  The original author probably would have been satisfied to use g.findNodeAnywhere, but the present code redoes the search every time, so in theory there could be multiple "Parameterized Nodes" nodes in the outline.  But that does not seem like a great idea...Anyway, there is no need for the self.params ivar.

3. I fixed some problems with the computation of pieces [1] in the parameterize method by adding extra calls to rstrip().  This ensures that ')' and '>' are properly removed.

All in all, I am not thrilled with this plugin: it seems bizarre to me.  Please let me know how it works for you.

Edward

Robert Shanley

unread,
Dec 17, 2014, 4:45:05 PM12/17/14
to leo-e...@googlegroups.com
My notion had been to use this plugin to parameterize test shell scripts. Unfortunately, section substitution, in a shell script, adds a newline so that something like

for f in << 1$ >> ; do ..... 

where << 1$ >> expands to xxx, becomes

for f in xxx
 ; do ....

Is there a way to prevent this behavior by suppressing the end of line for section substitution?

Thanks.
   

--
You received this message because you are subscribed to a topic in the Google Groups "leo-editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leo-editor/RIXIZdZ6ETs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Davy Cottet

unread,
Dec 17, 2014, 10:33:14 PM12/17/14
to leo-e...@googlegroups.com
Your need looks similar to mine.I think as well that would be very useful to implement.
https://github.com/leo-editor/leo-editor/issues/109

As a workaround, what if you put a " \ " when define your $1 ? Is that possible to obtain :

bobS

unread,
Jan 9, 2015, 2:06:11 PM1/9/15
to leo-e...@googlegroups.com
Attached is a version of macros.py that is a small tweak to what is in leo-master. Two lines are changed: 1) the regular expression is changed to properly capture multiple white-space-separated parameters and 2) the macro invocation body text is replaced by the body text of the macro definition node so that there are section references that can be replaced by the attached list of section definitions. Hopefully this makes things less bizarre.
macros.py

bobS

unread,
Jan 9, 2015, 2:06:39 PM1/9/15
to leo-e...@googlegroups.com
It turns out that the newline is being injected by section reference expansion, and is not a problem with macros. This is handled within leoTangle.py. I do not know whether output of this newline could be prevented. Putting a "\" at the end of a line does not work because it must follow the section reference which will have already put out the newline by the time the "\" is seen. So you get


for f in xxx
\ ; do ....

BobS

Edward K. Ream

unread,
Jan 22, 2015, 12:16:21 PM1/22/15
to leo-editor
On Fri, Jan 9, 2015 at 1:06 PM, bobS <rjsha...@gmail.com> wrote:

It turns out that the newline is being injected by section reference expansion, and is not a problem with macros. This is handled within leoTangle.py.

​Only if you are using @root nodes.  leoAtFile.py handles section references for @file and @nosent.

In general, the "extra" newlines are essential so that sentinels are on separate lines.  This can't be changed: sentinel lines are provably as simple as possible.

Edward

bobS

unread,
Jan 29, 2015, 3:51:11 PM1/29/15
to leo-e...@googlegroups.com
Thanks for the clarification, Edward.
Reply all
Reply to author
Forward
0 new messages