Пример #1
0
    def css_property_values(self, view, prefix, pos):
        prefix = css_prefixer(view, pos)
        prop   = find_css_property(view, pos)
        # These `values` are sourced from all the fully specified zen abbrevs
        # `d:n` => `display:none` so `display:n{tab}` will yield `none`
        values = css_property_values.get(prop)

        if values and prefix and prefix in values:
            oq_debug("zcprop:val prop: %r values: %r" % (prop, values))
            return [(prefix, v, v) for d,v in sorted(values.items())]
        else:
            # Look for values relating to that property
            # Remove exact matches, so a \t is inserted
            values =  [v for v in CSS_PROP_VALUES.get(prop, []) if v != prefix]
            if values:
                debug("zenmeta:val prop: %r values: %r" % (prop, values))
                return [(prefix, ':' + v, v) for v in values]
Пример #2
0
    def css_property_values(self, view, prefix, pos):
        prefix = css_prefixer(view, pos)
        prop   = find_css_property(view, pos)
        # These `values` are sourced from all the fully specified zen abbrevs
        # `d:n` => `display:none` so `display:n{tab}` will yield `none`
        values = css_property_values.get(prop)

        if values and prefix and prefix in values:
            oq_debug("zcprop:val prop: %r values: %r" % (prop, values))
            return [(prefix, v, v) for d,v in sorted(values.items())]
        else:
            # Look for values relating to that property
            # Remove exact matches, so a \t is inserted
            values =  [v for v in CSS_PROP_VALUES.get(prop, []) if v != prefix]
            if values:
                debug("zenmeta:val prop: %r values: %r" % (prop, values))
                return [(prefix, ':' + v, v) for v in values]
Пример #3
0
    def on_query_completions(self, view, prefix, locations):

        if (not self.correct_syntax(view)
                or zen_settings.get('disable_completions', False)):
            return []

        black_list = zen_settings.get('completions_blacklist', [])

        # We need to use one function rather than discrete listeners so as to
        # avoid pollution with less specific completions. Try to return early
        # with the most specific match possible.

        oq_debug("prefix: %r" % prefix)

        # A mapping of scopes, sub scopes and handlers, first matching of which
        # is used.
        COMPLETIONS = ((CSS_SELECTOR, self.css_selectors),
                       (CSS_VALUE, self.css_property_values),
                       (HTML_INSIDE_TAG, self.html_elements_attributes),
                       (HTML_INSIDE_TAG_ATTRIBUTE,
                        self.html_attributes_values))

        pos = view.sel()[0].b

        # Try to find some more specific contextual abbreviation
        for sub_selector, handler in COMPLETIONS:
            h_name = handler.__name__
            if h_name in black_list: continue
            if (view.match_selector(pos, sub_selector)
                    or view.match_selector(pos - 1, sub_selector)):
                c = h_name, prefix
                oq_debug('handler: %r prefix: %r' % c)
                oq_debug('pos: %r scope: %r' % (pos, view.syntax_name(pos)))

                completions = handler(view, prefix, pos)
                oq_debug('completions: %r' % completions)
                if completions:
                    if h_name == 'css_selectors':
                        return completions
                    else:
                        return completions  #, # NO_BUF | NO_PLUG)

        do_zen_expansion = True
        html_scope_for_zen = ("text.html meta.tag "
                              "-meta.scope.between-tag-pair.html "
                              "-punctuation.definition.tag.begin.html")

        if view.match_selector(pos, 'text.html'):
            if view.match_selector(pos, html_scope_for_zen):
                do_zen_expansion = False

        if do_zen_expansion:
            # Expand Zen expressions such as `d:n+m:a` or `div*5`
            try:

                abbr = zencoding.actions.basic.find_abbreviation(editor)
                oq_debug('abbr: %r' % abbr)
                if abbr and not view.match_selector(locations[0],
                                                    HTML_INSIDE_TAG):
                    result = expand_abbr(abbr)
                    oq_debug('expand_abbr abbr: %r result: %r' %
                             (abbr, result))

                    if result:
                        return (
                            [(abbr, result, result)],
                            # 0,
                            NO_BUF  #| NO_PLUG
                        )

            except ZenInvalidAbbreviation:
                pass

        # If it wasn't a valid Zen css snippet, or the prefix is empty ''
        # then get warm and fuzzy with css properties.

        # TODO, before or after this, fuzz directly against the zen snippets
        # eg  `tjd` matching `tj:d` to expand `text-justify:distribute;`

        if (view.match_selector(pos, CSS_PROPERTY)
                and not 'css_properties' in black_list):

            # Use this to get non \w based prefixes
            prefix = css_prefixer(view, pos)
            properties = sorted(CSS_PROP_VALUES.keys())
            # 'a'.startswith('') is True! so will never get IndexError below
            exacts = [p for p in properties if p.startswith(prefix)]

            if exacts: properties = exacts
            else:
                properties = [
                    p for p in properties if
                    # to allow for fuzzy, which will
                    # generally start with first letter
                    p.strip('-').startswith(prefix[0].lower())
                ]

            oq_debug('css_property exact: %r prefix: %r properties: %r' %
                     (bool(exacts), prefix, properties))

            return ([(prefix, v + '\t' + 'zen:css_properties', '%s:$1;' % v)
                     for v in properties], NO_BUF)
        else:
            return []
Пример #4
0
    def on_query_completions(self, view, prefix, locations):

        if ( not self.correct_syntax(view) or
             zen_settings.get('disable_completions', False) ): return []

        black_list = zen_settings.get('completions_blacklist', [])

        # We need to use one function rather than discrete listeners so as to
        # avoid pollution with less specific completions. Try to return early
        # with the most specific match possible.

        oq_debug("prefix: %r" % prefix)

        # A mapping of scopes, sub scopes and handlers, first matching of which
        # is used.
        COMPLETIONS = (
            (CSS_SELECTOR,              self.css_selectors),
            (CSS_VALUE,                 self.css_property_values),
            (HTML_INSIDE_TAG,           self.html_elements_attributes),
            (HTML_INSIDE_TAG_ATTRIBUTE, self.html_attributes_values) )

        pos = view.sel()[0].b

        # Try to find some more specific contextual abbreviation
        for sub_selector, handler in COMPLETIONS:
            h_name = handler.__name__
            if h_name in black_list: continue
            if ( view.match_selector(pos,  sub_selector) or
                 view.match_selector(pos -1,  sub_selector )):
                c = h_name, prefix
                oq_debug('handler: %r prefix: %r' % c)
                oq_debug('pos: %r scope: %r' % (pos, view.syntax_name(pos)))

                completions = handler(view, prefix, pos)
                oq_debug('completions: %r' % completions)
                if completions:
                    if h_name == 'css_selectors':
                        return completions
                    else:
                        return completions#, # NO_BUF | NO_PLUG)


        do_zen_expansion = True
        html_scope_for_zen = ("text.html meta.tag "
                "-meta.scope.between-tag-pair.html "
                "-punctuation.definition.tag.begin.html")

        if view.match_selector(pos, 'text.html'):
            if view.match_selector(pos, html_scope_for_zen):
                do_zen_expansion = False

        if do_zen_expansion:
            # Expand Zen expressions such as `d:n+m:a` or `div*5`
            try:

                abbr = zencoding.actions.basic.find_abbreviation(editor)
                oq_debug('abbr: %r' % abbr)
                if abbr and not view.match_selector( locations[0],
                                                     HTML_INSIDE_TAG ):
                    result = expand_abbr(abbr)
                    oq_debug('expand_abbr abbr: %r result: %r' % (abbr, result))

                    if result:
                        return  (

                             [(abbr, result, result)],
                             # 0,
                             NO_BUF #| NO_PLUG
                        )

            except ZenInvalidAbbreviation:
                pass

        # If it wasn't a valid Zen css snippet, or the prefix is empty ''
        # then get warm and fuzzy with css properties.

        # TODO, before or after this, fuzz directly against the zen snippets
        # eg  `tjd` matching `tj:d` to expand `text-justify:distribute;`

        if ( view.match_selector(pos, CSS_PROPERTY) and
             not 'css_properties' in black_list ):

            # Use this to get non \w based prefixes
            prefix     = css_prefixer(view, pos)
            properties = sorted(CSS_PROP_VALUES.keys())
            # 'a'.startswith('') is True! so will never get IndexError below
            exacts     = [p for p in properties if p.startswith(prefix)]

            if exacts: properties = exacts
            else:      properties = [ p for p in properties if
                                      # to allow for fuzzy, which will
                                      # generally start with first letter
                                      p.strip('-').startswith(prefix[0].lower()) ]

            oq_debug('css_property exact: %r prefix: %r properties: %r' % (
                      bool(exacts), prefix, properties ))

            return ([ (prefix, v +'\t'+'zen:css_properties', '%s:$1;' %  v) for v in properties ],
                     NO_BUF)
        else:
            return []
Пример #5
0
    def on_query_completions(self, view, prefix, locations):
        if not self.correct_syntax(view): return []

        # We need to use one function rather than discrete listeners so as to
        # avoid pollution with less specific completions. Try to return early
        # with the most specific match possible.

        oq_debug("prefix: %r" % prefix)

        # A mapping of scopes, sub scopes and handlers, first matching of which
        # is used.
        COMPLETIONS = (

            (CSS,  ( (CSS_SELECTOR,              self.css_selectors),
                     (CSS_VALUE,                 self.css_property_values) )),

            (HTML, ( (HTML_INSIDE_TAG,           self.html_elements_attributes),
                     (HTML_INSIDE_TAG_ATTRIBUTE, self.html_attributes_values) ))
        )

        pos = view.sel()[0].b

        # Try to find some more specific contextual abbreviation
        for root_selector, sub_selectors in COMPLETIONS:
            for sub_selector, handler in sub_selectors:
                if view.match_selector(pos,  sub_selector):

                    c = handler.__name__, prefix
                    oq_debug('handler: %r prefix: %r' % c)
                    oq_debug('pos: %r scope: %r' % (pos, view.syntax_name(pos)))

                    completions = handler(view, prefix, pos)
                    oq_debug('completions: %r' % completions)
                    if completions: return completions

        # Expand Zen expressions such as `d:n+m:a` or `div*5`
        try:
            abbr = zencoding.actions.basic.find_abbreviation(editor)
            oq_debug('abbr: %r' % abbr)

            if abbr:
                result = expand_abbr(abbr)
                oq_debug('expand_abbr abbr: %r result: %r' % (abbr, result))

                if result:
                    return [
                        (abbr, result if '<' not in result else abbr, result)]

        except ZenInvalidAbbreviation:
            pass

        # If it wasn't a valid Zen css snippet, or the prefix is empty ''
        # then get warm and fuzzy with css properties.

        # TODO, before or after this, fuzz directly against the zen snippets
        # eg  `tjd` matching `tj:d` to expand `text-justify:distribute;`

        if view.match_selector(pos, CSS_PROPERTY):
            # Use this to get non \w based prefixes
            prefix     = css_prefixer(view, pos)
            properties = sorted(CSS_PROP_VALUES.keys())
            # 'a'.startswith('') is True! so will never get IndexError below
            exacts     = [p for p in properties if p.startswith(prefix)]

            if exacts: properties = exacts
            else:      properties = [ p for p in properties if
                                      # to allow for fuzzy, which will
                                      # generally start with first letter
                                      p.strip('-').startswith(prefix[0].lower()) ]

            oq_debug('css_property exact: %r prefix: %r properties: %r' % (
                      bool(exacts), prefix, properties ))

            return [ (prefix, v, '%s:$1;' %  v) for v in properties ]
        else:
            return []