#325 <https://github.com/leo-editor/leo-editor/issues/325> recommends replacing per-file @cmd decorators with the global @g.command decorator.
There are over 300 commands to be munged, so it will pay to create helper scripts. This will save my body and avoid typos. The first script <https://github.com/leo-editor/leo-editor/issues/325#issuecomment-622966777> clones all @file nodes containing a definition of an @cmd decorator. The second script <https://github.com/leo-editor/leo-editor/issues/325#issuecomment-622967330> prints, for one particular @file node, what the proposed new code would be like. Eventually, it will actually change p.b. For example, given this node in leoApp.py: @cmd('exit-leo') @cmd('quit-leo') def onQuit(self, event=None): """Exit Leo, prompting to save unsaved outlines first.""" ### Rest of onQuit. The printed output is: ----- app.onQuit @g.command (exit-leo) def exit_leo(event): self.onQuit(event) def onQuit(self, event=None): """Exit Leo, prompting to save unsaved outlines first.""" if 'shutdown' in g.app.debug: g.trace() ### Rest of onQuit. This kind of script is much more flexible, and more reliable, than Leo abbreviations or emacs-like macros could be. As I write this, I see that more work is needed: 1. exit_leo does not follow the proper pattern (and "self" is undefined): @g.command('command-name') def a_Command(event): c = event.get('c') if not c: return ### get the instance of the proper class, usually from c. 2. The script might copy docstrings to the newly-created functions. 3. Oops, single quotes should surround the command name. These problems mirror possible manual editing mistakes. Much easier to correct the script than to fix by-hand typos. 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 on the web visit https://groups.google.com/d/msgid/leo-editor/297d35b7-2dcc-422a-ba74-790f6f27fc46%40googlegroups.com.
