From 0279ecfe6e22b4cd8b1c302b010a6e06e047d165 Mon Sep 17 00:00:00 2001 From: Adrian Lienhard Date: Mon, 10 Apr 2017 15:09:19 -0700 Subject: [PATCH] Improve exclusion Settings implementation - Make settings changes take effect without restarting Sublime - Rename the settings name to make it simpler - Move check into separate method - Fix path to default settings file in menu definition - Update README --- All Autocomplete.sublime-settings | 9 +++++---- Main.sublime-menu | 2 +- README.md | 21 +++++++++++++++++++++ all_views_completions.py | 25 ++++++++++++++++--------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/All Autocomplete.sublime-settings b/All Autocomplete.sublime-settings index 21a4fc3..e7df7cc 100644 --- a/All Autocomplete.sublime-settings +++ b/All Autocomplete.sublime-settings @@ -1,7 +1,8 @@ { - // An array of syntaxes to exclude from checking. Can be partial string, like "css" - // "exclude_scopes_from_complete_triggers": [ - // "css", - // "scss" + // An array of syntax names to exclude from being autocompleted. + // Can be a partial string, for instance, "css" would match scss code. + // "exclude_from_completion": [ + // "css", + // "scss" // ] } diff --git a/Main.sublime-menu b/Main.sublime-menu index a14365e..27c18a4 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -15,7 +15,7 @@ { "command": "open_file", "args": { - "file": "${packages}/SublimeAllAutocomplete/All Autocomplete.sublime-settings" + "file": "${packages}/All Autocomplete/All Autocomplete.sublime-settings" }, "caption": "Settings – Default" }, diff --git a/README.md b/README.md index c29a52d..c34a54c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,27 @@ You can also install this package manually by entering the Packages directory of git clone https://github.com/alienhard/SublimeAllAutocomplete +Settings +-------- + +You can disable the additional autocompletion provided by this package for specific source files and even select syntax within files. In the Sublime menu go to Preferences > Package Settings > All Autocomplete > Settings – User. + +Example: the following Setting would disable All Autocomplete for CSS and JavaScript code: + +``` +"exclude_from_completion": [ + "css", + "js" +] +``` + +The names provided in this list are matched against the so-called "syntax scope" of the currently autocompleted input. For example, in a CSS file, when you start typing a new CSS class name, the syntax scope is "source.css meta.selector.css". The names you provide in the config above are partially matched against this scope. This means, you can completely disable All Autocomplete for all CSS code by specifying "css" – or you can disable it only for specific parts, for example, CSS selectors by specifying "selector.css". Or to disable completion in comments, include "comment" in the list. + +Note, if you want to disable it in C source, but not in CSS, add "source.c" in the list (since "c" alone would also match css). + +You can find the syntax scope of code at the current cursor position with Control+Shift+P. + + LICENSE ------- diff --git a/all_views_completions.py b/all_views_completions.py index 11631f3..57a9ad0 100644 --- a/all_views_completions.py +++ b/all_views_completions.py @@ -7,9 +7,6 @@ import time from os.path import basename -settings = sublime.load_settings('All Autocomplete.sublime-settings') -exclude_scopes = settings.get("exclude_scopes_from_complete_triggers", []) - # limits to prevent bogging down the system MIN_WORD_SIZE = 3 MAX_WORD_SIZE = 50 @@ -19,15 +16,16 @@ MAX_FIX_TIME_SECS_PER_VIEW = 0.01 +def plugin_loaded(): + global settings + settings = sublime.load_settings('All Autocomplete.sublime-settings') + class AllAutocomplete(sublime_plugin.EventListener): def on_query_completions(self, view, prefix, locations): - - # bypass if in ignored syntax list - for exclude_scope in exclude_scopes: - if view.scope_name(locations[0]).find(exclude_scope) != -1: - return - + if is_disabled_in(view.scope_name(locations[0])): + return [] + words = [] # Limit number of views but always include the active view. This @@ -46,6 +44,7 @@ def on_query_completions(self, view, prefix, locations): words += [(w, v) for w in view_words] words = without_duplicates(words) + matches = [] for w, v in words: trigger = w @@ -56,6 +55,13 @@ def on_query_completions(self, view, prefix, locations): return matches +def is_disabled_in(scope): + excluded_scopes = settings.get("exclude_from_completion", []) + for excluded_scope in excluded_scopes: + if scope.find(excluded_scope) != -1: + return True + return False + def filter_words(words): words = words[0:MAX_WORDS_PER_VIEW] return [w for w in words if MIN_WORD_SIZE <= len(w) <= MAX_WORD_SIZE] @@ -112,5 +118,6 @@ def fix_truncation(view, words): def is_empty_match(match): return match.empty() else: + plugin_loaded() def is_empty_match(match): return match is None