# Buggy code
def openEmptyWorkBook(self):
    """Open an empty frame and paste the contents of CheatSheet.leo into it."""
    lm = self
    # Create an empty frame.
    fn = lm.computeWorkbookFileName()
    c = lm.loadLocalFile(fn, gui=g.app.gui, old_c=None)
    # Open the cheatsheet, but not in batch mode.
    if not g.app.batchMode and not g.os_path_exists(fn):
        # #933: Save clipboard.
        old_clipboard = g.app.gui.getTextFromClipboard()
        # Paste the contents of CheetSheet.leo into c.
        c2 = c.openCheatSheet(redraw=False)
        if c2:
            for p2 in c2.rootPosition().self_and_siblings():
                c2.selectPosition(p2)
                c2.copyOutline()
                p = c.pasteOutline()
                c.selectPosition(p)
                p.contract()
                p.clearDirty()
            c2.close(new_c=c)
            root = c.rootPosition()
            if root.h == g.shortFileName(fn):
                root.doDelete(newNode=root.next())
            p = g.findNodeAnywhere(c, "Leo's cheat sheet")
            if p:
                c.selectPosition(p)
                p.expand()
            c.target_language = "rest"
            # Settings not parsed the first time.
            c.setChanged(False)
            c.redraw()
        # #933: Restore clipboard
        g.app.gui.replaceClipboardWith(old_clipboard)
    return c


# Traceback (AttributeError)
(leo-dev) matt@SURFACE C:\Users\mattw\t
leo-m

Leo 6.0-devel, devel branch, build e86b1c87b6
2019-06-13 17:47:36 -0500
Using default leo file name:
C:/Users/mattw/t/.leo/workbook.leo
OleSetClipboard: Failed to set mime data (text/plain) on clipboard: COM error 0xffffffff800401d0  (Unknown error 0x0800401d0) (The parameter is incorrect.) selectPosition Warning: no p run,load,doPostPluginsInit,openEmptyWorkBook
Traceback (most recent call last):
File "c:\apps\miniconda3\envs\leo-dev\Scripts\leo-m-script.py", line 11, in <module>
load_entry_point('leo', 'console_scripts', 'leo-m')()
File "c:\users\mattw\code\leo-editor\leo\core\runLeo.py", line 73, in run
g.app.loadManager.load(fileName, pymacs)
File "c:\users\mattw\code\leo-editor\leo\core\leoApp.py", line 2375, in load

ok = lm.doPostPluginsInit()
File "c:\users\mattw\code\leo-editor\leo\core\leoApp.py", line 2433, in doPostPluginsInit
c1 = lm.openEmptyWorkBook()
File "c:\users\mattw\code\leo-editor\leo\core\leoApp.py", line 2488, in openEmptyWorkBook
p.contract()
AttributeError: 'NoneType' object has no attribute 'contract'

# Fixed code
def openEmptyWorkBook(self):
    """Open an empty frame and paste the contents of CheatSheet.leo into it."""
    lm = self
    # Create an empty frame.
    fn = lm.computeWorkbookFileName()
    c = lm.loadLocalFile(fn, gui=g.app.gui, old_c=None)
    if not c:
        return None  # #1201: AttributeError below.
    # Open the cheatsheet, but not in batch mode.
    if not g.app.batchMode and not g.os_path_exists(fn):
        # #933: Save clipboard.
        old_clipboard = g.app.gui.getTextFromClipboard()
        # Paste the contents of CheetSheet.leo into c.
        c2 = c.openCheatSheet(redraw=False)
        if c2:
            for p2 in c2.rootPosition().self_and_siblings():
                c2.selectPosition(p2)
                c2.copyOutline()
                p = c.pasteOutline()
                c.selectPosition(p)
                p.contract()
                p.clearDirty()
            c2.close(new_c=c)
            root = c.rootPosition()
            if root.h == g.shortFileName(fn):
                root.doDelete(newNode=root.next())
            p = g.findNodeAnywhere(c, "Leo's cheat sheet")
            if p:
                c.selectPosition(p)
                p.expand()
            c.target_language = "rest"
            # Settings not parsed the first time.
            c.setChanged(False)
            c.redraw()
        # #933: Restore clipboard
        g.app.gui.replaceClipboardWith(old_clipboard)
    return c