Permalink
Browse files

Tweaked Tab expander

  • Loading branch information...
1 parent 593ed48 commit d3558a638c9e272ff18a1090e4d5561633558189 @sergeche committed Nov 15, 2012
Showing with 125 additions and 42 deletions.
  1. +25 −4 Default (Linux).sublime-keymap
  2. +25 −4 Default (OSX).sublime-keymap
  3. +25 −4 Default (Windows).sublime-keymap
  4. +6 −1 Emmet.sublime-settings
  5. +1 −6 editor.js
  6. +19 −17 emmet-plugin.py
  7. +24 −6 misc/generate-keymap.py
@@ -53,7 +53,7 @@
"command": "run_emmet_action",
"context": [
{
- "operand": "source.css -source.css.less, text.xml, text.html - source",
+ "operand": "source.css - source.css.less, text.xml, text.html",
"operator": "equal",
"match_all": true,
"key": "selector"
@@ -356,11 +356,17 @@
"command": "expand_abbreviation_by_tab",
"context": [
{
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal",
"match_all": true,
"key": "selector"
},
+ {
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": true,
+ "key": "selector"
+ },
{
"match_all": true,
"key": "selection_empty"
@@ -396,11 +402,17 @@
"command": "expand_abbreviation_by_tab",
"context": [
{
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal",
"match_all": true,
"key": "selector"
},
+ {
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": true,
+ "key": "selector"
+ },
{
"match_all": true,
"key": "selection_empty"
@@ -436,15 +448,24 @@
"command": "handle_enter_key",
"context": [
{
- "operand": "text.html -source, text.xml",
+ "operand": "text.html, text.xml",
+ "match_all": true,
+ "key": "selector"
+ },
+ {
+ "operand": "text.html source, php",
+ "operator": "not_equal",
+ "match_all": true,
"key": "selector"
},
{
"operand": false,
+ "match_all": true,
"key": "auto_complete_visible"
},
{
"operand": false,
+ "match_all": true,
"key": "setting.disable_formatted_linebreak"
}
]
@@ -53,7 +53,7 @@
"command": "run_emmet_action",
"context": [
{
- "operand": "source.css -source.css.less, text.xml, text.html - source",
+ "operand": "source.css - source.css.less, text.xml, text.html",
"operator": "equal",
"match_all": true,
"key": "selector"
@@ -356,11 +356,17 @@
"command": "expand_abbreviation_by_tab",
"context": [
{
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal",
"match_all": true,
"key": "selector"
},
+ {
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": true,
+ "key": "selector"
+ },
{
"match_all": true,
"key": "selection_empty"
@@ -396,11 +402,17 @@
"command": "expand_abbreviation_by_tab",
"context": [
{
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal",
"match_all": true,
"key": "selector"
},
+ {
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": true,
+ "key": "selector"
+ },
{
"match_all": true,
"key": "selection_empty"
@@ -436,15 +448,24 @@
"command": "handle_enter_key",
"context": [
{
- "operand": "text.html -source, text.xml",
+ "operand": "text.html, text.xml",
+ "match_all": true,
+ "key": "selector"
+ },
+ {
+ "operand": "text.html source, php",
+ "operator": "not_equal",
+ "match_all": true,
"key": "selector"
},
{
"operand": false,
+ "match_all": true,
"key": "auto_complete_visible"
},
{
"operand": false,
+ "match_all": true,
"key": "setting.disable_formatted_linebreak"
}
]
@@ -53,7 +53,7 @@
"command": "run_emmet_action",
"context": [
{
- "operand": "source.css -source.css.less, text.xml, text.html - source",
+ "operand": "source.css - source.css.less, text.xml, text.html",
"operator": "equal",
"match_all": true,
"key": "selector"
@@ -356,11 +356,17 @@
"command": "expand_abbreviation_by_tab",
"context": [
{
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal",
"match_all": true,
"key": "selector"
},
+ {
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": true,
+ "key": "selector"
+ },
{
"match_all": true,
"key": "selection_empty"
@@ -396,11 +402,17 @@
"command": "expand_abbreviation_by_tab",
"context": [
{
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal",
"match_all": true,
"key": "selector"
},
+ {
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": true,
+ "key": "selector"
+ },
{
"match_all": true,
"key": "selection_empty"
@@ -436,15 +448,24 @@
"command": "handle_enter_key",
"context": [
{
- "operand": "text.html -source, text.xml",
+ "operand": "text.html, text.xml",
+ "match_all": true,
+ "key": "selector"
+ },
+ {
+ "operand": "text.html source, php",
+ "operator": "not_equal",
+ "match_all": true,
"key": "selector"
},
{
"operand": false,
+ "match_all": true,
"key": "auto_complete_visible"
},
{
"operand": false,
+ "match_all": true,
"key": "setting.disable_formatted_linebreak"
}
]
View
@@ -18,6 +18,11 @@
// abbreviation expander should be disabled
"disable_tab_abbreviations_for_scopes": "",
+ // A regexp for scope name: if it matches, Tab handler won’t work
+ // The reason to use this preference is that ST2 has buggy scope matcher
+ // which may still trigger Tab handler even if it's restricted by context
+ "disable_tab_abbreviations_for_regexp": "source\\..+?\\stext\\.html",
+
// Exit tabstop mode when enter key is pressed
"clear_fields_on_enter_key": true,
@@ -39,7 +44,7 @@
// If entered abbreviation (like `php`) wasn’t found in Emmet snippets list
// or "known_html_tags" preference, Tab handler will not be triggered.
// Leave this setting black to disable this feature
- "disabled_single_snippet_for_scopes": "text.html - source",
+ "disabled_single_snippet_for_scopes": "text.html",
// A space separated list of all known HTML tags,
// used together with "disabled_on_single_snippets" option
View
@@ -87,17 +87,12 @@ var editorProxy = emmet.exec(function(require, _) {
getProfileName: function() {
var view = activeView();
-
- var profile = view.settings()['emmet.profile'] || null;
- if (profile)
- return profile;
-
var pos = this.getCaretPos();
if (view.match_selector(pos, 'text.xml') || view.match_selector(pos, 'xsl'))
return 'xml';
- if (view.match_selector(pos, 'source')) {
+ if (view.score_selector(pos, 'source string')) {
return 'line';
}
View
@@ -285,33 +285,31 @@ def on_query_context(self, view, key, op, operand, match_all):
if key != 'is_abbreviation':
return None
- is_valid_context = check_context()
- handle_key = should_handle_tab_key()
- log('Tab handler invoked')
- log('Valid context -- %s' % is_valid_context)
- log('Should handle Tab key -- %s' % handle_key)
-
- if not is_valid_context or not handle_key:
+ if not check_context() or not should_handle_tab_key():
return False
- # print(view.syntax_name(view.sel()[0].begin()))
-
# we need to filter out attribute completions if
# 'disable_completions' option is not active
if (not settings.get('disable_completions', False) and
self.correct_syntax(view) and
self.completion_handler(view)):
- return False
+ return None
+
+ caret_pos = view.sel()[0].begin()
+ cur_scope = view.syntax_name(caret_pos)
# let's see if Tab key expander should be disabled for current scope
banned_scopes = settings.get('disable_tab_abbreviations_for_scopes', '')
- log('Banned scopes -- %s' % banned_scopes)
- log('Current scope -- %s' % view.syntax_name(view.sel()[0].begin()))
- if banned_scopes and view.match_selector(view.sel()[0].b, banned_scopes):
- return False
+ if banned_scopes and view.score_selector(caret_pos, banned_scopes):
+ return None
+
+ # Sometimes ST2 matcher may corectly filter scope context,
+ # check it against special regexp
+ banned_regexp = settings.get('disable_tab_abbreviations_for_regexp', None)
+ if banned_regexp and re.search(banned_regexp, cur_scope):
+ return None
return run_action(lambda i, sel: ctx.js().locals.pyRunAction('expand_abbreviation'))
- # return ctx.js().locals.pyRunAction('expand_abbreviation')
def on_query_completions(self, view, prefix, locations):
if ( not self.correct_syntax(view) or
@@ -466,9 +464,13 @@ def run(self, edit, **kw):
# let's see if we have to insert formatted linebreak
caret_pos = view.sel()[0].begin()
scope = view.syntax_name(caret_pos)
- if sublime.score_selector(scope, settings.get('formatted_linebreak_scopes', '')) > 0:
+ if sublime.score_selector(scope, settings.get('formatted_linebreak_scopes', '')):
snippet = '\n\t${0}\n'
- else:
+
+ # Looks like ST2 has buggy scope matcher: sometimes it will call
+ # this action even if context selector forbids that.
+ # Thus, we have to manually filter it.
+ elif 'source.' not in scope:
# checking a special case: caret right after opening tag,
# but not exactly between pairs
if view.substr(sublime.Region(caret_pos - 1, caret_pos)) == '>':
View
@@ -14,7 +14,7 @@
"pc": "ctrl+shift+forward_slash",
"context": [{
"key": "selector",
- "operand": "source.css -source.css.less, text.xml, text.html - source",
+ "operand": "source.css - source.css.less, text.xml, text.html",
"operator": "equal"
}]
},
@@ -63,8 +63,13 @@
{
"key": "selector",
"match_all": True,
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal"
+ }, {
+ "key": "selector",
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": True
}, {
"key": "selection_empty",
"match_all": True
@@ -98,8 +103,13 @@
{
"key": "selector",
"match_all": True,
- "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html - source - keyword.control.php, text.haml, string",
+ "operand": "source.css, source.sass, source.less, source.scss, source.stylus, text.xml, text.html, text.haml, source string",
"operator": "equal"
+ }, {
+ "key": "selector",
+ "operand": "text.html source",
+ "operator": "not_equal",
+ "match_all": True
}, {
"key": "selection_empty",
"match_all": True
@@ -132,13 +142,21 @@
"context": [
{
"key": "selector",
- "operand": "text.html -source, text.xml"
+ "operand": "text.html, text.xml",
+ "match_all": True
+ }, {
+ "key": "selector",
+ "operand": "text.html source, php",
+ "operator": "not_equal",
+ "match_all": True
}, {
"key": "auto_complete_visible",
- "operand": False
+ "operand": False,
+ "match_all": True
}, {
"key": "setting.disable_formatted_linebreak",
- "operand": False
+ "operand": False,
+ "match_all": True
}
]
},

0 comments on commit d3558a6

Please sign in to comment.