def guess_filetype(parm):
    """Infer a filetype from the snippet parameter.

    If the `editorlang` key exists, try that first. Otherwise, try to
    guess based on the node's type. If neither match well, return an
    empty string.

    :param parm: Paramter containing the snippet
    :type parm: :class:`hou.Parm`
    :return: Suggested file extension
    :rtype: str
    """
    exts = {
        "python": ".py",
        "vex": ".h",
        "opencl": ".cl",
    }

    editorlang = parm.parmTemplate().tags().get("editorlang")
    if editorlang:
        return exts[editorlang.lower()]

    # Try by node type
    type_map = {
        "wrangle": exts["vex"],
        "python": exts["python"],
        "opencl": exts["opencl"]
    }
    for searchterm, ext in type_map.items():
        if searchterm in parm.node().type().nameComponents()[2]:
            return ext
    return ""