atombender / sublime_text_alternative_autocompletion

Adds TextMate-like autocompletion to Sublime Text 2 and 3.
MIT License
147 stars 23 forks source link

Populate candidates with sensible defaults (feature request) #8

Closed colinta closed 12 years ago

colinta commented 12 years ago

This is especially handy in PHP, where I often type array_m + ESC, and expect array_merge (or array_map) to appear, even though it's not in by buffer. In name-spaced languages like python this would be trickier, but could still useful I think. Anyway, implementation is easy enough.

My idea is that a list of words could "seed" the candidates variable in the find_candidates function. I'm imagining a system that uses built-ins and the user's language-specific settings file, so that this list could be configured per-language.

Built-in config files are easy enough:

view = self.window.active_view()
settings_name, _ = os.path.splitext(os.path.basename(view.settings().get('syntax')))
default_settings = sublime.load_settings("alternative_autocompletion.sublime-settings")
candidates = default_settings[settings_name]

And to make things even better, combine that list with User/__language__.sublime-settings.

user_settings = sublime.load_settings(settings_name + ".sublime-settings")
candidates = candidates.extend(user_settings['autocomplete'])  # extend?  override?

The built-in settings file is simple enough:

{
    "php": ["array_merge", "array_map", "..."],
    "python": ["splitext", "..."]
}

And user settings:

{
  // ...
  "autocomplete": ["entitize", "..."],
  //...
}
colinta commented 12 years ago

I've taken a stab at this. See pull request https://github.com/alexstaubo/sublime_text_alternative_autocompletion/pull/9.