Home Download Buy Blog Forum Support

Snippet, Word Seperator and Other - Please Help :)

Snippet, Word Seperator and Other - Please Help :)

Postby frodzet on Mon May 27, 2013 12:59 pm

Hey,

First of all, i'm not quiete sure if this is the right place to post this, anyways i'll give it a try:

I'm "developing" a package for World of Warcraft. Now some API Reference looks like e.g

GameTooltip:SetOwner(some arguments)

This means that typing GameTooltip and pressing : will seperate the word - now if i type SetOwner nothing appears on my completion file, however if i go and remove the : from the word seperator in the settings file everything shows properly but double clicking either on GameTooltip or Setowner will select it all.

Is there a way to make snippets trigger on the words after the Seperator sign also. Or maybe a way to make .sublime-completions file Case Sensitive + providing descriptions like in snippets?

Thank you very much in advance!
frodzet
 
Posts: 6
Joined: Mon May 27, 2013 12:09 pm

Re: Snippet, Word Seperator and Other - Please Help :)

Postby malkomalko on Thu Jun 06, 2013 6:25 pm

I'm also very interested in this as it'd allow for more user friendly completions for most languages.
malkomalko
 
Posts: 13
Joined: Sat Feb 02, 2013 12:54 pm

Re: Snippet, Word Seperator and Other - Please Help :)

Postby FichteFoll on Thu Jun 06, 2013 9:38 pm

You can create descriptions for completions by placing a \t tab chracater in the "trigger" key. Everything after that will be displayed on the right like with snippets.

What do you mean with CaseSensitive? Do you want the completion to only trigger when case is matched? I don't think you can do that.

The only way I can think of that handles completions containing a word-separator is probably with an EventListener.on_query_completions plugin.
FichteFoll
 
Posts: 406
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Snippet, Word Seperator and Other - Please Help :)

Postby frodzet on Fri Jun 07, 2013 2:48 pm

FichteFoll wrote:You can create descriptions for completions by placing a \t tab chracater in the "trigger" key. Everything after that will be displayed on the right like with snippets.

What do you mean with CaseSensitive? Do you want the completion to only trigger when case is matched? I don't think you can do that.

The only way I can think of that handles completions containing a word-separator is probably with an EventListener.on_query_completions plugin.


Allright so i tried this, and it worked just properly until the word contained a word seperator, e.g:

something.something\t(something, something);

now typing in something and pressing the tab would work just properly, however if i type in something.something and tab then it would write:

something.something.something(something, something)

any possible fix for this?
frodzet
 
Posts: 6
Joined: Mon May 27, 2013 12:09 pm

Re: Snippet, Word Seperator and Other - Please Help :)

Postby FichteFoll on Fri Jun 07, 2013 10:13 pm

No, that's what I've been saying. At least not with usual completions.

The only way I can think of that handles completions containing a word-separator is probably with an EventListener.on_query_completions plugin.


This is because completions are only interpreted to the first word seperator character. So, what you need to do is write an API completion than can get text beyond the word separator (the "."). See "Packages/HTML/html_completions.py" for a pretty nice example.
FichteFoll
 
Posts: 406
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Snippet, Word Seperator and Other - Please Help :)

Postby frodzet on Fri Jun 07, 2013 11:59 pm

FichteFoll wrote:No, that's what I've been saying. At least not with usual completions.

The only way I can think of that handles completions containing a word-separator is probably with an EventListener.on_query_completions plugin.


This is because completions are only interpreted to the first word seperator character. So, what you need to do is write an API completion than can get text beyond the word separator (the "."). See "Packages/HTML/html_completions.py" for a pretty nice example.



A nice example of what, exactly?
frodzet
 
Posts: 6
Joined: Mon May 27, 2013 12:09 pm

Re: Snippet, Word Seperator and Other - Please Help :)

Postby FichteFoll on Sat Jun 08, 2013 12:20 am

Okay, let me phrase it like this: In order to do what you want to you have to write a Python plugin.

If you are not known to Python, well, go ahead and learn it, it's awesome.

If you are, I think you can put some sense into these examples (with the API documentation):

API: http://www.sublimetext.com/docs/2/api_reference.html
Docs on plugins: http://docs.sublimetext.info/en/latest/ ... ugins.html
Specifically about completion plugins: http://docs.sublimetext.info/en/latest/ ... tions-list

More advanced example from "Packages/HTML/html_completions.py":
Code: Select all
# This responds to on_query_completions, but conceptually it's expanding
# expressions, rather than completing words.
#
# It expands these simple expressions:
# tag.class
# tag#id
class HtmlCompletions(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        # Only trigger within HTML
        if not view.match_selector(locations[0],
                "text.html - source - meta.tag, punctuation.definition.tag.begin"):
            return []

        # Get the contents of each line, from the beginning of the line to
        # each point
        lines = [view.substr(sublime.Region(view.line(l).a, l))
            for l in locations]

        # Reverse the contents of each line, to simulate having the regex
        # match backwards
        lines = [l[::-1] for l in lines]

        # Check the first location looks like an expression
        rex = re.compile("([\w-]+)([.#])(\w+)")
        expr = match(rex, lines[0])
        if not expr:
            return []

        # Ensure that all other lines have identical expressions
        for i in xrange(1, len(lines)):
            ex = match(rex, lines[i])
            if ex != expr:
                return []

        # Return the completions
        arg, op, tag = rex.match(expr).groups()

        arg = arg[::-1]
        tag = tag[::-1]
        expr = expr[::-1]

        if op == '.':
            snippet = "<{0} class=\"{1}\">$1</{0}>$0".format(tag, arg)
        else:
            snippet = "<{0} id=\"{1}\">$1</{0}>$0".format(tag, arg)

        return [(expr, snippet)]
FichteFoll
 
Posts: 406
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Snippet, Word Seperator and Other - Please Help :)

Postby frodzet on Fri Jun 14, 2013 4:49 pm

FichteFoll wrote:Okay, let me phrase it like this: In order to do what you want to you have to write a Python plugin.

If you are not known to Python, well, go ahead and learn it, it's awesome.

If you are, I think you can put some sense into these examples (with the API documentation):

API: http://www.sublimetext.com/docs/2/api_reference.html
Docs on plugins: http://docs.sublimetext.info/en/latest/ ... ugins.html
Specifically about completion plugins: http://docs.sublimetext.info/en/latest/ ... tions-list

More advanced example from "Packages/HTML/html_completions.py":
Code: Select all
# This responds to on_query_completions, but conceptually it's expanding
# expressions, rather than completing words.
#
# It expands these simple expressions:
# tag.class
# tag#id
class HtmlCompletions(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        # Only trigger within HTML
        if not view.match_selector(locations[0],
                "text.html - source - meta.tag, punctuation.definition.tag.begin"):
            return []

        # Get the contents of each line, from the beginning of the line to
        # each point
        lines = [view.substr(sublime.Region(view.line(l).a, l))
            for l in locations]

        # Reverse the contents of each line, to simulate having the regex
        # match backwards
        lines = [l[::-1] for l in lines]

        # Check the first location looks like an expression
        rex = re.compile("([\w-]+)([.#])(\w+)")
        expr = match(rex, lines[0])
        if not expr:
            return []

        # Ensure that all other lines have identical expressions
        for i in xrange(1, len(lines)):
            ex = match(rex, lines[i])
            if ex != expr:
                return []

        # Return the completions
        arg, op, tag = rex.match(expr).groups()

        arg = arg[::-1]
        tag = tag[::-1]
        expr = expr[::-1]

        if op == '.':
            snippet = "<{0} class=\"{1}\">$1</{0}>$0".format(tag, arg)
        else:
            snippet = "<{0} id=\"{1}\">$1</{0}>$0".format(tag, arg)

        return [(expr, snippet)]


Thanks ill look into that :)
frodzet
 
Posts: 6
Joined: Mon May 27, 2013 12:09 pm


Return to Plugin Development

Who is online

Users browsing this forum: Majestic-12 [Bot], Yahoo [Bot] and 5 guests