# Buggy code
def computeThemeFilePath(self):
    """Return the absolute path to the theme .leo file."""
    lm = self
    resolve = self.resolve_theme_path
    # Step 1: Use the --theme file if it exists
    path = resolve(lm.options.get("theme_path"), tag="--theme")
    if path:
        return path
    # Step 2: look for the @string theme-name setting in the first loaded file.
    # This is a hack, but especially useful for test*.leo files in leo/themes.
    path = lm.files and lm.files[0]
    if path and g.os_path_exists(path):
        # Tricky: we must call lm.computeLocalSettings *here*.
        theme_c = lm.openSettingsFile(path)
        if not theme_c:
            return None  # Fix #843.
        settings_d, junk_shortcuts_d = lm.computeLocalSettings(
            c=theme_c,
            settings_d=lm.globalSettingsDict,
            bindings_d=lm.globalBindingsDict,
            localFlag=False,
        )
        setting = settings_d.get_string_setting("theme-name")
        if setting:
            tag = theme_c.shortFileName()
            path = resolve(setting, tag=tag)
            if path:
                return path
    # Finally, use the setting in myLeoSettings.leo.
    setting = lm.globalSettingsDict.get_string_setting("theme-name")
    tag = "myLeoSettings.leo"
    return resolve(setting, tag=tag)


# Traceback (xml.etree.ElementTree.ParseError)
setting leoID from os.getenv('USER'): 'matt'
reading settings in /home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/config/leoSettings.leo
reading settings in /home/matt/.leo/myLeoSettings.leo
QApplication: invalid style override passed, ignoring it.

Leo 5.8 b1, build 20180815095610, Wed, Aug 15, 2018  9:56:10 AM
Not running from a git repo
Python 3.6.6, PyQt version 5.11.1
linux
** isPython3: True

reading settings in /home/matt/.leo/workbook.leo
loadOnePlugin: leo.plugins.livecode.init() returned False
reading settings in /home/matt/code/leo-editor/leo/dist/leoDist.leo
Traceback (most recent call last):

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoCommands.py", line 2072, in executeAnyCommand
return command(event)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoGlobals.py", line 269, in commander_command_wrapper
method(event=event)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/commands/commanderFileCommands.py", line 214, in open
c2 = g.openWithFileName(fileName, old_c=c)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoGlobals.py", line 3682, in openWithFileName
return g.app.loadManager.loadLocalFile(fileName, gui, old_c)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoApp.py", line 3059, in loadLocalFile
previousSettings = lm.getPreviousSettings(fn)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoApp.py", line 1973, in getPreviousSettings
c = lm.openSettingsFile(fn)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoApp.py", line 2139, in openSettingsFile
readAtFileNodesFlag=False, silent=True)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoFileCommands.py", line 631, in openLeoFile
silent=silent,

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoFileCommands.py", line 494, in getLeoFile
v = FastRead(c, self.gnxDict).readFile(fileName)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoFileCommands.py", line 68, in readFile
return self.readWithElementTree(s)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/site-packages/leo/core/leoFileCommands.py", line 73, in readWithElementTree
xroot = ElementTree.fromstring(contents)

File "/home/matt/miniconda3/envs/leo/lib/python3.6/xml/etree/ElementTree.py", line 1314, in XML
parser.feed(text)

File "<string>", line None

xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 189, column 1

# Fixed code
def computeThemeFilePath(self):
    """Return the absolute path to the theme .leo file."""
    lm = self
    resolve = self.resolve_theme_path
    #
    # Step 1: Use the --theme file if it exists
    path = resolve(lm.options.get("theme_path"), tag="--theme")
    if path:
        return path
    #
    # Step 2: look for the @string theme-name setting in the first loaded file.
    # This is a hack, but especially useful for test*.leo files in leo/themes.
    path = lm.files and lm.files[0]
    if path and g.os_path_exists(path):
        # Tricky: we must call lm.computeLocalSettings *here*.
        theme_c = lm.openSettingsFile(path)
        if theme_c:
            settings_d, junk_shortcuts_d = lm.computeLocalSettings(
                c=theme_c,
                settings_d=lm.globalSettingsDict,
                bindings_d=lm.globalBindingsDict,
                localFlag=False,
            )
            setting = settings_d.get_string_setting("theme-name")
            if setting:
                tag = theme_c.shortFileName()
                path = resolve(setting, tag=tag)
                if path:
                    return path
    #
    # Finally, use the setting in myLeoSettings.leo.
    setting = lm.globalSettingsDict.get_string_setting("theme-name")
    tag = "myLeoSettings.leo"
    return resolve(setting, tag=tag)