Sublime Forum

How to add autocomplete kywords

#1

Hi,
I’m trying to add syntax highlight and autocomplete for a markup language which is an extension to HTML so basically it is HTML with a few extra tags.
I’ve created a .tmLanguage file which extends html

<dict> <key>include</key> <string>text.html.basic</string> </dict>

And it seems to be working fine. Now i would like to add autocomplete for the extra tags as HTML has (html_completions.py) so i copied html_completions.py to my package/myml_completions.py

import sublime, sublime_plugin
import re

def match(rex, str):
    m = rex.match(str)
    if m:
        return m.group(0)
    else:
        return None

# Provide completions that match just after typing an opening angle bracket
class TagCompletions(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        # Only trigger within MYML
        if not view.match_selector(locations[0], "text.myml - source"):
            return ]

        pt = locations[0] - len(prefix) - 1
        ch = view.substr(sublime.Region(pt, pt + 1))
        if ch != '<':
            return ]

        return (
            ("myset\tTag", "myset name=\"$1\" value=\"$2\" />")
        ], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)

But it doesn’t seem to work. If i start typing <mys the autocomplete menu does not appear as it does when i edit HTML files and type <for
Any ideea how can i do this?

0 Likes

#2

Hmmm everything looks fine to me.

I did something similar for ColdFusion markup language.
You can compare what I’ve done here github.com/SublimeText/ColdFusion

It might help narrow down the problem for you.

0 Likes

#3

Thanks. I followed your example and now it seems to be working.

0 Likes

#4

i was also having the same problem at first but thanks to the help of other members here i was able to get mine working as well. sometimes all it takes is a help of another genius mind to be able to solve such problems. i am glad that we are getting a lot of help and feedback around here because it really helps a lot especially for newbies like me. Hopefully i can be of help too :smile:

0 Likes