# Buggy code
def init_config(self):
    """Init docutils settings."""
    ds = {}
    gc = self.c.config

    def getConfig(getfun, name, default, setfun=None, setvar=None):
        """Make a shorthand way to get and store a setting with defaults"""
        r = getfun("vr_" + name)  # keep docutils name but prefix
        if setfun:  # settings are held in Qactions
            if r:
                setfun(r)
            else:
                setfun(default)
        elif setvar:  # Just setting a variable
            if r:
                setvar = r
            else:
                setvar = default
        else:  # settings held in dict (for docutils use)
            if r:
                ds[name] = r
            else:
                ds[name] = default

    # Do docutils config (note that the vr_ prefix is omitted)

    getConfig(gc.getString, "stylesheet_path", "")
    getConfig(gc.getInt, "halt_level", 6)
    getConfig(gc.getInt, "report_level", 5)
    getConfig(gc.getString, "math_output", "mathjax")
    getConfig(gc.getBool, "smart_quotes", True)
    getConfig(gc.getBool, "embed_stylesheet", True)
    getConfig(gc.getBool, "xml_declaration", False)
    # Additional docutils values suggested by T P <wingusr@gmail.com>
    getConfig(gc.getString, "syntax_highlight", "long")
    getConfig(gc.getBool, "no_compact_lists", False)
    getConfig(gc.getBool, "no_compact_field_lists", False)
    # Do VR2 init values
    getConfig(gc.getBool, "verbose", False, self.verbose_mode_action.setChecked)
    getConfig(gc.getBool, "tree_mode", False, self.tree_mode_action.setChecked)
    getConfig(gc.getBool, "auto_update", True, self.auto_mode_action.setChecked)
    getConfig(gc.getBool, "lock_node", False, self.lock_mode_action.setChecked)
    getConfig(gc.getBool, "slideshow", False, self.slideshow_mode_action.setChecked)
    getConfig(gc.getBool, "visible_code", True, self.visible_code_action.setChecked)
    getConfig(gc.getBool, "execute_code", False, self.execute_code_action.setChecked)
    getConfig(gc.getBool, "rest_code_output", False, self.reST_code_action.setChecked)
    # Misc other internal settings
    # Mark of the Web (for IE) to allow sensible security options
    # getConfig(gc.getBool, 'include_MOTW', True, setvar=self.MOTW)
    return ds


# Traceback (NameError)
Traceback (most recent call last):
File "c:\leo.repo\leo-editor\leo\core\leoGlobals.py", line 2385, in new_cmd_wrapper
func(self, event=event)
File "c:\leo.repo\leo-editor\leo\commands\helpCommands.py", line 62, in help
self.c.putHelpFor(rst_s)
File "c:\leo.repo\leo-editor\leo\core\leoCommands.py", line 2322, in putHelpFor
g.app.gui.put_help(c, s, short_title)
File "c:\leo.repo\leo-editor\leo\plugins\qt_gui.py", line 1055, in put_help
vr.show_scrolled_message(tag='Apropos', kw=kw)
File "c:\leo.repo\leo-editor\leo\plugins\viewrendered2.py", line 299, in show_scrolled_message
vr = viewrendered(event=kw)
NameError: name 'viewrendered' is not defined

# Fixed code
def init_config(self):
    """Init docutils settings."""
    ds = {}
    gc = self.c.config

    def getConfig(getfun, name, default, setfun=None, setvar=None):
        """Make a shorthand way to get and store a setting with defaults"""
        r = getfun("vr_" + name)  # keep docutils name but prefix
        if setfun:  # settings are held in Qactions
            if r:
                setfun(r)
            else:
                setfun(default)
        elif setvar:  # Just setting a variable
            if r:
                setvar = r
            else:
                setvar = default
        else:  # settings held in dict (for docutils use)
            if r:
                ds[name] = r
            else:
                ds[name] = default

    # Do docutils config (note that the vr_ prefix is omitted)

    getConfig(gc.getString, "stylesheet_path", "")
    getConfig(gc.getInt, "halt_level", 6)
    getConfig(gc.getInt, "report_level", 5)
    getConfig(gc.getString, "math-output", "mathjax")
    getConfig(gc.getBool, "smart_quotes", True)
    getConfig(gc.getBool, "embed_stylesheet", True)
    getConfig(gc.getBool, "xml_declaration", False)
    # Additional docutils values suggested by T P <wingusr@gmail.com>
    getConfig(gc.getString, "syntax_highlight", "long")
    getConfig(gc.getBool, "no_compact_lists", False)
    getConfig(gc.getBool, "no_compact_field_lists", False)

    # Markdown values: tbp
    # This is a bit of a kludge, but getConfig() does not
    # know about "self", and this way is easier than figuring out
    # how to get a reference to the WenViewPlus instance.
    def set_bg_color(color):
        global MD_RENDERING_BG_COLOR
        MD_RENDERING_BG_COLOR = color

    getConfig(gc.getString, "md-rendering-pane-background-color", "black", set_bg_color)

    # Do VR2 init values
    getConfig(gc.getBool, "verbose", False, self.verbose_mode_action.setChecked)
    getConfig(gc.getBool, "tree_mode", False, self.tree_mode_action.setChecked)
    getConfig(gc.getBool, "auto_update", True, self.auto_mode_action.setChecked)
    getConfig(gc.getBool, "lock_node", False, self.lock_mode_action.setChecked)
    getConfig(gc.getBool, "slideshow", False, self.slideshow_mode_action.setChecked)
    getConfig(gc.getBool, "visible_code", True, self.visible_code_action.setChecked)
    getConfig(gc.getBool, "code_only", False, self.code_only_action.setChecked)

    getConfig(gc.getBool, "execute_code", False, self.execute_code_action.setChecked)
    getConfig(gc.getBool, "rest_code_output", False, self.reST_code_action.setChecked)
    # Misc other internal settings
    # Mark of the Web (for IE) to allow sensible security options
    # getConfig(gc.getBool, 'include_MOTW', True, setvar=self.MOTW)
    return ds