示例#1
0
 def check_context(view):
     abbr        =       zencoding.actions.basic.find_abbreviation(editor)
     if abbr:
         try:            result = expand_abbr(abbr)
         except          ZenInvalidAbbreviation: return None
         if result:
             return result
示例#2
0
 def check_context(view):
     abbr        =       zencoding.actions.basic.find_abbreviation(editor)
     if abbr:
         try:            result = expand_abbr(abbr)
         except          ZenInvalidAbbreviation: return None
         if result:
             return abbr, result
    def run(self, edit, doctype=None):
        view     = self.view
        syntax   = zen_settings.get( 'default_html_syntax',
                                     'Packages/HTML/HTML.tmlanguage' )
        view.set_syntax_file(syntax)

        view.run_command( 'insert_snippet',
                          {'contents': expand_abbr('html:%s' % doctype)} )
示例#4
0
    def run(self, edit, doctype=None):
        view     = self.view
        syntax   = zen_settings.get( 'default_html_syntax',
                                     'Packages/HTML/HTML.tmlanguage' )
        view.set_syntax_file(syntax)
        view.run_command( 'insert_snippet',
                          {'contents': expand_abbr('html:%s' % doctype)} )

################################################################################
    def run_command(self, view, cmd_input):
        try:
            ex = expand_abbr(cmd_input, super_profile="no_check_valid")
            p = editor.get_profile_name() + ".no_check_valid"
            if not ex.strip():
                raise ZenInvalidAbbreviation("Empty expansion %r" % ex)
        except Exception:
            return False

        view.run_command("run_zen_action", dict(action="wrap_with_abbreviation", abbr=cmd_input, profile_name=p))
    def run_command(self, view, cmd_input):
        try:
            ex = expand_abbr(cmd_input, super_profile='no_check_valid')
            p = editor.get_profile_name() + '.no_check_valid'
            if not ex: raise ZenInvalidAbbreviation('Empty expansion %r' % ex)
        except ZenInvalidAbbreviation:
            return False

        view.run_command (
            'run_zen_action',
            dict(action="wrap_with_abbreviation", abbr=cmd_input, profile_name=p))
示例#7
0
    def run_command(self, view, cmd_input):
        try:
            ex = expand_abbr(cmd_input, super_profile='no_check_valid')
            p = editor.get_profile_name() + '.no_check_valid'
            if not ex: raise ZenInvalidAbbreviation('Empty expansion %r' % ex)
        except ZenInvalidAbbreviation:
            return False

        view.run_command (
            'run_zen_action',
            dict(action="wrap_with_abbreviation", abbr=cmd_input, profile_name=p))
示例#8
0
    def run(self, prop_value=False):
        window = self.window
        view = window.active_view()

        if prop_value:
            pos = view.sel()[0].b
            prop = find_css_property(window.active_view(), pos)
            forpanel = sorted((css_property_values.get(prop) or {}).items())
            contents = lambda i: forpanel[i][1]
            # TODO expand while selector matches
            "meta.property-value.css - punctuation"
            # Then insert snippet over top of selection
        else:
            forpanel = css_sorted
            contents = lambda i: expand_abbr(forpanel[i][0])

        def done(i):
            if i != -1:
                view.run_command('insert_snippet', {'contents': contents(i)})

        display = [[v, k] for k, v in forpanel]
        window.show_quick_panel(display, done)
示例#9
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 []
示例#10
0
 def filter_input(self, abbr):
     try:
         return expand_abbr(abbr, super_profile='no_check_valid')
     except Exception:
         "dont litter the console"