Sublime Forum

Snippet, Word Seperator and Other - Please Help :)

#1

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!

0 Likes

#2

I’m also very interested in this as it’d allow for more user friendly completions for most languages.

0 Likes

#3

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.

0 Likes

#4

[quote=“FichteFoll”]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.[/quote]

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?

0 Likes

#5

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

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.

0 Likes

#6

[quote=“FichteFoll”]No, that’s what I’ve been saying. At least not with usual completions.

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.[/quote]

A nice example of what, exactly?

0 Likes

#7

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: sublimetext.com/docs/2/api_reference.html
Docs on plugins: docs.sublimetext.info/en/latest/ … ugins.html
Specifically about completion plugins: docs.sublimetext.info/en/latest/ … tions-list

More advanced example from “Packages/HTML/html_completions.py”:

[code]# 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*)
        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)][/code]*
0 Likes

#8

[quote=“FichteFoll”]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: sublimetext.com/docs/2/api_reference.html
Docs on plugins: docs.sublimetext.info/en/latest/ … ugins.html
Specifically about completion plugins: docs.sublimetext.info/en/latest/ … tions-list

More advanced example from “Packages/HTML/html_completions.py”:

[code]# 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*)
        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)][/code]*

Thanks ill look into that :smile:[/quote]

0 Likes