def _getSmartIndenter(indenterName, qpart, indenter):
    """Get indenter by name.
    Available indenters are none, normal, cstyle, haskell, lilypond, lisp, python, ruby, xml
    Indenter name is not case sensitive
    Raise KeyError if not found
    indentText is indentation, which shall be used. i.e. '\t' for tabs, '    ' for 4 space symbols
    """
    indenterName = indenterName.lower()

    if indenterName in ('haskell', 'lilypond'):  # not supported yet
        logger.warning('Smart indentation for %s not supported yet. But you could be a hero who implemented it' % indenterName)
        from qutepart.indenter.base import IndentAlgNormal as indenterClass
    elif 'none' == indenterName:
        from qutepart.indenter.base import IndentAlgBase as indenterClass
    elif 'normal' == indenterName:
        from qutepart.indenter.base import IndentAlgNormal as indenterClass
    elif 'cstyle' == indenterName:
        from qutepart.indenter.cstyle import IndentAlgCStyle as indenterClass
    elif 'python' == indenterName:
        from qutepart.indenter.python import IndentAlgPython as indenterClass
    elif 'ruby' == indenterName:
        from qutepart.indenter.ruby import IndentAlgRuby as indenterClass
    elif 'xml' == indenterName:
        from qutepart.indenter.xmlindent import IndentAlgXml as indenterClass
    elif 'haskell' == indenterName:
        from qutepart.indenter.haskell import IndenterHaskell as indenterClass
    elif 'lilypond' == indenterName:
        from qutepart.indenter.lilypond import IndenterLilypond as indenterClass
    elif 'lisp' == indenterName:
        from qutepart.indenter.lisp import IndentAlgLisp as indenterClass
    elif 'scheme' == indenterName:
        from qutepart.indenter.scheme import IndentAlgScheme as indenterClass
    else:
        raise KeyError("Indenter %s not found" % indenterName)

    return indenterClass(qpart, indenter)
def _buildvisitdir(kindpats):
    """Try to build an efficient visitdir function

    Return a visitdir function if it's built. Otherwise return None
    if there are unsupported patterns.

    >>> _buildvisitdir([('include', 'foo', '')])
    >>> _buildvisitdir([('relglob', 'foo', '')])
    >>> t = _buildvisitdir([
    ...     ('glob', 'a/b', ''),
    ...     ('glob', 'c/*.d', ''),
    ...     ('glob', 'e/**/*.c', ''),
    ...     ('re', '^f/(?!g)', ''), # no "$", only match prefix
    ...     ('re', '^h/(i|j)$', ''),
    ...     ('glob', 'i/a*/b*/c*', ''),
    ...     ('glob', 'i/a5/b7/d', ''),
    ...     ('glob', 'j/**.c', ''),
    ... ])
    >>> t('a')
    True
    >>> t('a/b')
    'all'
    >>> t('a/b/c')
    'all'
    >>> t('c')
    True
    >>> t('c/d')
    False
    >>> t('c/rc.d')
    'all'
    >>> t('c/rc.d/foo')
    'all'
    >>> t('e')
    True
    >>> t('e/a')
    True
    >>> t('e/a/b.c')
    True
    >>> t('e/a/b.d')
    True
    >>> t('f')
    True
    >>> t('f/g')
    False
    >>> t('f/g2')
    False
    >>> t('f/g/a')
    False
    >>> t('f/h')
    'all'
    >>> t('f/h/i')
    'all'
    >>> t('h/i')
    True
    >>> t('h/i/k')
    False
    >>> t('h/k')
    False
    >>> t('i')
    True
    >>> t('i/a1')
    True
    >>> t('i/b2')
    False
    >>> t('i/a/b2/c3')
    'all'
    >>> t('i/a/b2/d4')
    False
    >>> t('i/a5/b7/d')
    'all'
    >>> t('j/x/y')
    True
    >>> t('z')
    False
    """
    tree = _tree()
    for kind, pat, _source in kindpats:
        if kind == "glob":
            components = []
            for p in pat.split("/"):
                if "[" in p or "{" in p or "*" in p or "?" in p:
                    break
                components.append(p)
            prefix = "/".join(components)
            matchrecursive = prefix == pat
            tree.insert(
                prefix,
                matchrecursive=matchrecursive,
                globpats=_remainingpats(pat, prefix),
            )
        elif kind == "re":
            # Still try to get a plain prefix from the regular expression so we
            # can still have fast paths.
            if pat.startswith("^"):
                # "re" already matches from the beginning, unlike "relre"
                pat = pat[1:]
            components = []
            for p in pat.split("/"):
                if re.escape(p) != p:
                    # contains special characters
                    break
                components.append(p)
            prefix = "/".join(components)
            tree.insert(
                prefix, matchrecursive=False, repats=_remainingpats(pat, prefix)
            )
        else:
            # Unsupported kind
            return None
    return tree.visitdir