Skip to content

Commit

Permalink
Improve exclusion Settings implementation
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
alienhard committed Apr 11, 2017
1 parent bc8319b commit 0279ecf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
9 changes: 5 additions & 4 deletions All Autocomplete.sublime-settings
Original file line number Diff line number Diff line change
@@ -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"
// ]
}
2 changes: 1 addition & 1 deletion Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
25 changes: 16 additions & 9 deletions all_views_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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

0 comments on commit 0279ecf

Please sign in to comment.