Sublime Forum

If lots of sublime-completions, then variable names never sh

#1

I am quite shocked that Sublime has “Words in the buffer” set at the lowest priority to show in the completions list. The words in the buffer contain the variables that you are currently using for your current program. Those are the most likely to be used with the highest occurrence. For Sublime to instead show a long list of all the available function names and all the other crap from the .sublime-completions file is very inconvenient.

Because of this, I am having to remove and not use my .sublime-completions files. Because when I am typing in a variable name that I am using in my current program - I want it to show up in the auto-completion list so I don’t have to keep typing that variable-name - but that variable from the buffer contents shows up very late in the sublime-completions list because it always gets superceded by all the other completions from all the other sources.

What about an option to have “Words in the buffer” as the first priority displayed auto completions in the auto completion list?

From: docs.sublimetext.info/en/latest/ … tions.html

[quote]This is the order in which completions are prioritized:

  • Snippets
  • API-injected completions
  • .sublime-completions files
  • Words in the buffer[/quote]
0 Likes

#2

Related:

​​https://forum.sublimetext.com/t/if-lots-of-sublime-completions-then-variable-names-never-sh/10936/1

​​http://sublimetext.userecho.com/topic/151308-change-completion-priority/

​​http://sublimetext.userecho.com/topic/115795-snippets-always-take-priority-over-autocomplete/

​​http://sublimetext.userecho.com/topic/116149-autocomplete-snippets-shadow-variables-with-the-same-name/

0 Likes

#3

+1
But I guess a plugin EventListener.on_query_completions() will be able to insert Words in Buffer to the top
something similar to this: https://sublimetext.com/forum/viewtopic.php?f=3&t=11687
But I’m so incompetent at Py

0 Likes

#4

[quote=“Binocular222”]+1
But I guess a plugin EventListener.on_query_completions() will be able to insert Words in Buffer to the top
something similar to this: https://sublimetext.com/forum/viewtopic.php?f=3&t=11687
But I’m so incompetent at Py[/quote]

[quote]This is the order in which completions are prioritized:

  • Snippets
  • API-injected completions
  • .sublime-completions files
  • Words in the buffer[/quote]

So it seems you can return additional completions from on_query_completions which would then take the #2 Rank of “API-injected completions”.
And we can disable “Words in the buffer” via flag - “sublime.INHIBIT_WORD_COMPLETIONS”.
But how to get the “Words from Buffer” completion-list in Python and return it from on_query_completions so that those completions would take the rank of “API-injected completions”?

Here’s a start, can’t figure out how to get the “Words from Buffer” completion list in Python.

import sublime
import sublime_plugin

class CustomCompletionListener(sublime_plugin.EventListener):
    def on_query_completions(self, view, prefix, locations):
        return (], sublime.INHIBIT_WORD_COMPLETIONS)
0 Likes

#5

Tried this, with code borrowed from here but the words still are not prioritized above the entries in .sublime-completions files
So seems this is not possible until developer prioritizes this.

[code]import sublime
import sublime_plugin
import re

class CustomCompletionListener(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
code = view.substr(sublime.Region(0, view.size()))
words = set(re.findall(r’\b[A-Za-z_]\w+\b’, code))
return (words, sublime.INHIBIT_WORD_COMPLETIONS)
[/code]

Ideally, I would like my completions list to show with following priority:

  1. API-injected completions
  2. Words in Buffer
    3 .sublime-completions files
  3. Snippets
0 Likes