sublime-drupal-autocomplete
sublime-drupal-autocomplete copied to clipboard
Non-Drupal projects
Are you able to enable/disable this plugin on a project-by-project basis? Not all of my projects are Drupal-based, so for those this module doesn't need to run.
+1
One method would be to only run when a project has the work 'drupal' in it's name. But that would break backwards compatibility with existing modules. Open to suggestions.
I also work on different types of projects ranging from Drupal to Django to Rails, so having that Drupal completion file loading into my projects really bugged me so I tried to stop it ;)
I won't have the time to code this (for pull request) until next week or after but I achieved this by adding a project setting flag, not sure if its the best way to achieve this but its simple. Placing code below just incase anyone wants to add it to the repo before I have time (hint hint).
Starting at line 65 in DPCompletions.py
def on_post_save(self, view):
if view.settings().get("drupal_project_autocomplete") == False:
path = view.file_name()
rootPath = None
if path:
# Try to find the myproject.sublime-project file
for filename in ['*.sublime-project']:
rootPath = self.find_file(path, filename)
if rootPath:
threads = []
thread = ProjectCompletionsScan(rootPath, 5)
threads.append(thread)
thread.start()
def on_query_completions(self, view, prefix, locations):
if view.settings().get("drupal_project_autocomplete") == False:
if not view.match_selector(locations[0], "source.php"):
return []
path = view.file_name()
completions_location = None
if path:
# Try to find the Drupal.sublime-completions file
for filename in ['*.sublime-projectcompletions']:
completions_location = self.find_file(path, filename)
if completions_location:
fp = open(completions_location, 'r')
t = ()
data = []
line = fp.readline()
while len(line) != 0:
e1, e2 = line.split("\t")
if re.match(prefix, e1, re.IGNORECASE):
t = e1, e2.rstrip()
data.append(t)
line = fp.readline()
fp.close()
return data
else:
return []
Then you can add this into your project settings on a per project basis: "drupal_project_autocomplete": false
If you don't add that to your project settings everything will work as normal, maybe, hopefully, it did for me :)
Thanks very much for this idea, sorry its taken so long to reply. I don't really use Sublime Text much these days so its low on my priority list. I've just committed something similar to what you have above, but rather than wrapping the whole function in a conditional I'm bailing out with returns. I've also flipped it around so that if the setting "drupal_project_autocomplete_ignore" is true then don't activate the plugin's completions. I think this makes it clearer what the setting does.
If you can test the latest commit on master branch which includes these changes that would be great.
5c8e4a68b05a2726c3c7cb458ad892bc0efe3e44