'Return all available element names beginning with expr'

def _completion_names_from_scope(self, expr, scoperef):

    self.log('_completion_names_from_scope::    %r,    scoperef:    %r', expr, scoperef)
    all_completions = {}
    keywords = self.langintel.langinfo.keywords
    for name in keywords:
        if ((not expr) or name.startswith(expr)):
            all_completions[name] = 'keyword'
    loopcount = (-1)
    while (scoperef and (scoperef[0] is not None)):
        loopcount += 1
        self.log('_completion_names_from_scope::    checking    scoperef:    %r', scoperef)
        elem = self._elem_from_scoperef(scoperef)
        if (elem is None):
            continue
        for name in elem.names:
            if (name and name.startswith(expr)):
                if (name not in all_completions):
                    hit_elem = elem.names[name]
                    if (loopcount and ('__local__' in hit_elem.get('attributes', '').split())):
                        continue
                    all_completions[name] = (hit_elem.get('ilk') or hit_elem.tag)
        scoperef = self.parent_scoperef_from_scoperef(scoperef)
    cplns = self.stdlib.toplevel_cplns(prefix=expr)
    for (ilk, name) in cplns:
        if (name not in all_completions):
            all_completions[name] = ilk
    for lib in self.libs:
        self.log('_completion_names_from_scope::    include    everything    from    lib:    %r', lib)
        cplns = lib.toplevel_cplns(prefix=expr)
        for (ilk, name) in cplns:
            if (name not in all_completions):
                all_completions[name] = ilk
    return [(ilk, name) for (name, ilk) in all_completions.items()]
