​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

-- 
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/3a65d252-3963-4190-8456-121ce2e822d4o%40googlegroups.com.

Reply via email to