Breakthroughs re leoInteg

44 views
Skip to first unread message

Edward K. Ream

unread,
Jul 18, 2020, 10:39:15 AM7/18/20
to leo-editor
​Hi Félix,

Wow, I didn't expect things to get so much easier so quickly. I have now graduated from newbie status! The breakthroughs:

1. I realized I could set breakpoints in leobridgeserver.py from within vs code.

Somehow I thought that doing so would trip a timeout, but it doesn't.

2. I realized that print statements must have a flush kwarg if they are are to appear immediately.

This clears up a lot of confusion.

3. I improved the error messages in the main function in leobridgeserver.py:

except websockets.exceptions.ConnectionClosedError:
   
print("Websocket connection closed", flush=True)
except Exception:
   
print('Exception in leobridgeserver.py!', flush=True)
   
# Like g.es_exception()...
    typ
, val, tb = sys.exc_info()
   
for line in traceback.format_exception(typ, val, tb):
       
print(line.rstrip(), flush=True)
finally:
    asyncio
.get_event_loop().stop()

This is a big one. It immediately revealed why Leo's git-diff command wasn't working. I changed it's signature to event=None, and voilà, it now just works.

4. The (now misnamed) LeoBridgeIntegController.outlineCommand can now call any method from Leo's core, provided they can be called with no arguments:

def outlineCommand(self, p_command, p_ap, p_keepSelection=False):
   
"""
    Generic call to a method in Leo's Commands class or any subcommander class.

    p_command: a method name (a string).
    p-node: (p_ap), an archived position.
    p_keepSelection: preserve the current selection.
    """

   
if not p_ap:
       
return self.outputError(f"Error in {p_command}: no param p_ap")
    w_p
= self.ap_to_p(p_ap)
   
if not w_p:
       
return self.outputError(f"Error in {p_command}: no w_p node found")
    w_func
= self.get_commander_method(p_command)
   
if not w_func:
       
return self.outputError(f"Error in {p_command}: no method found")
   
if w_p == self.commander.p:
        w_func
()
   
else:
        oldPosition
= self.commander.p
       
self.commander.selectPosition(w_p)
        w_func
()
       
if p_keepSelection and self.commander.positionExists(oldPosition):
           
self.commander.selectPosition(oldPosition)  
   
return self.outputPNode(self.commander.p)

# Compatibility.
leoCommand
= outlineCommand

bc.get_commander_method helper is:

def get_commander_method(self, p_command):
   
""" Return the given method (p_command) in the Commands class or subcommanders."""
   
# First, try the commands class.
    w_func
= getattr(self.commander, p_command, None)
   
if w_func:
       
return w_func
   
# Search all subcommanders for the method.
    table
= (  # This table comes from c.initObjectIvars.
       
'abbrevCommands',
       
'bufferCommands',
       
'chapterCommands',
       
'controlCommands',
       
'convertCommands',
       
'debugCommands',
       
'editCommands',
       
'editFileCommands',
       
'evalController',
       
'gotoCommands',
       
'helpCommands',
       
'keyHandler',
       
'keyHandlerCommands',
       
'killBufferCommands',
       
'leoCommands',
       
'leoTestManager',
       
'macroCommands',
       
'miniBufferWidget',
       
'printingController',
       
'queryReplaceCommands',
       
'rectangleCommands',
       
'searchCommands',
       
'spellCommands',
       
'vimCommands',  # Not likely to be useful.
   
)
   
for ivar in table:
        subcommander
= getattr(self.commander, ivar, None)
       
if subcommander:
            w_func
= getattr(subcommander, p_command, None)
           
if w_func:
               
return w_func
       
else:
           
print(f"get_commander_method: not Found: c.{ivar}", flush=True) # Should never happen.
   
return None

The code is in the git-diff branch of the leoInteg project. I'll merge it into the ekr branch next.

Edward

Edward K. Ream

unread,
Jul 18, 2020, 11:14:16 AM7/18/20
to leo-editor
On Saturday, July 18, 2020 at 9:39:15 AM UTC-5, Edward K. Ream wrote:

> It immediately revealed why Leo's git-diff command wasn't working. I changed it's signature to event=None, and voilà, it now just works.

It's in devel, at rev 3435c19.

Edward

Edward K. Ream

unread,
Jul 18, 2020, 11:21:23 AM7/18/20
to leo-editor
On Saturday, July 18, 2020 at 9:39:15 AM UTC-5, Edward K. Ream wrote:

> The code is in the git-diff branch of the leoInteg project. I'll merge it into the ekr branch next.

Done. I have deleted the git-diff branch on my local machine.

Edward
Reply all
Reply to author
Forward
0 new messages