'extract scope for each char in line wo dups, ineffective but it works?'

def extracting_scopes(self, edit, region, scope_name=''):

    scopes = []
    for p in range((region.b - region.a)):
        p += region.a
        sr = self.view.extract_scope(p)
        if ((sr.a < region.a) or ((sr.b - 1) > region.b)):
            if (scopes and (p == scopes[(~ 0)].b)):
                sr = sublime.Region(p, region.b)
            else:
                sr = sublime.Region(region.a, region.b)
        if (sr not in scopes):
            scopes.append(sr)
        elif (scopes and (self.view.scope_name(p) != self.view.scope_name(scopes[(~ 0)].a))):
            scopes.append(sublime.Region(p, region.b))
        if (scopes and (sr.a < scopes[(~ 0)].b) and ((p - 1) == scopes[(~ 0)].b)):
            scopes.append(sublime.Region(scopes[(~ 0)].b, sr.b))
    if (scopes and (scopes[(~ 0)].b > region.b)):
        scopes[(~ 0)] = sublime.Region(scopes[(~ 0)].a, region.b)
    if (len(scopes) > 1):
        if scopes[0].intersects(scopes[1]):
            scopes[0] = sublime.Region(scopes[0].a, scopes[1].a)
        if ((scopes[(~ 0)].b < region.b) or (scopes[(~ 0)].a < region.a)):
            scopes.append(sublime.Region(scopes[(~ 0)].b, region.b))
        new_scopes = scopes[:0:(~ 0)]
        for (i, s) in enumerate(new_scopes):
            if s.intersects(scopes[(~ (i + 1))]):
                if (scopes[(~ (i + 1))].b < s.b):
                    scopes[(~ i)] = sublime.Region(scopes[(~ (i + 1))].b, s.b)
                    new_scopes[i] = scopes[(~ i)]
                else:
                    scopes[(~ (i + 1))] = sublime.Region(scopes[(~ (i + 1))].a, s.a)
                    if (len(new_scopes) > (i + 1)):
                        new_scopes[(i + 1)] = scopes[(~ (i + 1))]
    return scopes
