SB: Leonine alternatives to emacs macros

51 views
Skip to first unread message

Edward K. Ream

unread,
Oct 31, 2020, 12:57:33 PM10/31/20
to leo-editor
#1413 was originally a request for reinstating emacs-style macros. I'm not likely to do that. Emacs macros are seldom used, and they are not very powerful without even more nerdy (non-existent) extensions such as emacs registers.

Instead, I shall attempt to make it easier to write Leonine scripts that change body text.

For example, I recently worked on the php colorizer in leo/modes/php.py. This involved renaming groups of rules in a systematic way. Neither emacs macros nor regular expressions come anywhere close to handling this task. So a Leonine script is required.

While thinking about such scripts, I reviewed Leo's resources for changing body text. What I found was a mess of overlapping, ugly code. Substantial refactoring is in order. The goal will be to create a pattern something like this:

u = c.undoer

data
= u.beforeChangeBody()
<< change p.b >>
c
.afterChangeBody(undo_type, data)

This pattern should replace all calls to LeoBody.onBodyChanged and c.updateBodyPane. A guiding principle will be to avoid keyword arguments (kwargs) wherever possible.

There are complexities involved that I won't discuss here. We shall see what happens :-)

Edward

Félix

unread,
Oct 31, 2020, 9:09:12 PM10/31/20
to leo-editor
I was using afterChangeNodeContents instead of afterChangeBody in leoInteg when modifying the body pane... (I''m currently trying to debug the first modif of the first node changed that seem to fail) I'm gonna try with this afterChangeBody instead :)
--
Félix

Edward K. Ream

unread,
Nov 1, 2020, 8:09:22 AM11/1/20
to leo-editor
On Sat, Oct 31, 2020 at 8:09 PM Félix <felix...@gmail.com> wrote:
I was using afterChangeNodeContents instead of afterChangeBody in leoInteg when modifying the body pane... (I''m currently trying to debug the first modif of the first node changed that seem to fail) I'm gonna try with this afterChangeBody instead :)

Sorry to mislead you. afterChangeBody does not exist, and I had overlooked afterChangeNodeContents.

I suspect before/afterChangeNodeContents will suffice, perhaps after being extended.

Edward

Félix

unread,
Nov 1, 2020, 1:51:31 PM11/1/20
to leo-editor
Thanks ! I'll try some more stuff! 

(There's always some small insignificant detail that's a blocker when working on a relatively big project - while the killer features were implemented easily! lol!)

--
Félix

Edward K. Ream

unread,
Nov 2, 2020, 5:19:50 AM11/2/20
to leo-editor
On Sun, Nov 1, 2020 at 12:51 PM Félix <felix...@gmail.com> wrote:
Thanks ! I'll try some more stuff! 

Oh good :-)

Edward
Reply all
Reply to author
Forward
0 new messages