def function_completions(<EOL>completion_text: str,<EOL>bel_spec: BELSpec,<EOL>function_list: list,<EOL>bel_fmt: str,<EOL>size: int,<EOL>) -> list:
<EOL>if isinstance(function_list, list):<EOL><INDENT>if bel_fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>function_list = [<EOL>bel_spec["<STR_LIT>"]["<STR_LIT>"][fn] for fn in function_list<EOL>]<EOL><DEDENT>else:<EOL><INDENT>function_list = [<EOL>bel_spec["<STR_LIT>"]["<STR_LIT>"][fn] for fn in function_list<EOL>]<EOL><DEDENT><DEDENT>elif bel_fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>function_list = bel_spec["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL><DEDENT>else:<EOL><INDENT>function_list = bel_spec["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL><DEDENT>matches = []<EOL>for f in function_list:<EOL><INDENT>escaped_completion_text = completion_text.replace(r"<STR_LIT:(>", r"<STR_LIT>").replace(<EOL>r"<STR_LIT:)>", r"<STR_LIT>"<EOL>)<EOL>log.debug(f"<STR_LIT>")<EOL>if re.match(escaped_completion_text, f):<EOL><INDENT>matches.append(f)<EOL><DEDENT><DEDENT>replace_list = []<EOL>for match in matches:<EOL><INDENT>if completion_text:<EOL><INDENT>highlight = match.replace(completion_text, f"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>highlight = completion_text<EOL><DEDENT>replace_list.append(<EOL>{<EOL>"<STR_LIT>": match,<EOL>"<STR_LIT:label>": f"<STR_LIT>",<EOL>"<STR_LIT>": highlight,<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>}<EOL>)<EOL><DEDENT>return replace_list[:size]<EOL>
Filter BEL functions by prefix

    Args:
        prefix: completion string
        bel_fmt: short, medium, long BEL formats
        spec: BEL specification

    Returns:
        list: list of BEL functions that match prefix