Permalink
Browse files

Lots of improvements

* New HTML matcher, works well with empty HTML tags like <br>, <img>
* Better syntax and output profile detection
* Inline CSS detection, e.g. abbreviations inside style="" attribute
* Fixed bug with user CSS completions
  • Loading branch information...
1 parent 5f66b71 commit 1651c0f49fbfa84d8775c6f631047465ab237e60 @sergeche committed Dec 4, 2012
Showing with 509 additions and 429 deletions.
  1. +8 −0 Default.sublime-commands
  2. +16 −12 editor.js
  3. +23 −8 emmet-plugin.py
  4. +462 −409 emmet/emmet-app.js
View
@@ -29,6 +29,14 @@
},
{
+ "caption": "Emmet: Go to Matching Pair",
+ "command": "run_emmet_action",
+ "args": {
+ "action": "matching_pair"
+ }
+ },
+
+ {
"caption": "Emmet: Next Edit Point",
"command": "run_emmet_action",
"args": {
View
@@ -85,14 +85,14 @@ var editorProxy = emmet.exec(function(require, _) {
// * Python's multiline block
// * CoffeeScript string
// * PHP heredoc
- return null;
+ return pyDetectProfile();
}
if (view.score_selector(pos, 'source string')) {
return 'line';
}
- return null;
+ return pyDetectProfile();
},
prompt: function(title) {
@@ -192,15 +192,15 @@ function pyCaptureWrappingRange() {
if (startOffset == endOffset) {
// no selection, find tag pair
- var matcher = require('html_matcher');
- range = matcher(info.content, startOffset, info.profile);
-
- if (!range || range[0] == -1) // nothing to wrap
+ var match = require('htmlMatcher').find(info.content, startOffset);
+ if (!match) {
+ // nothing to wrap
return null;
+ }
/** @type Range */
var utils = require('utils');
- var narrowedSel = utils.narrowToNonSpace(info.content, range[0], range[1] - range[0]);
+ var narrowedSel = utils.narrowToNonSpace(info.content, match.range);
startOffset = narrowedSel.start;
endOffset = narrowedSel.end;
}
@@ -294,15 +294,19 @@ function pyGetSyntax() {
return 'xsl';
}
+ var syntax = 'html';
+
// detect CSS-like syntaxes independently,
// since it may cause collisions with some highlighters
if (/\b(less|scss|sass|css|stylus)\b/.test(scope)) {
- return RegExp.$1;
+ syntax = RegExp.$1;
+ } else if (/\b(html|xml|haml)\b/.test(scope)) {
+ syntax = RegExp.$1;
}
- if (/\b(html|xml|haml)\b/.test(scope)) {
- return RegExp.$1;
- }
+ return require('actionUtils').detectSyntax(editorProxy, syntax);
+}
- return 'html';
+function pyDetectProfile(argument) {
+ return require('actionUtils').detectProfile(editorProxy);
}
View
@@ -114,6 +114,7 @@ def update_settings():
ctx.reset()
ctx.load_user_data(json.dumps(payload))
+ ctx.js()
def should_perform_action(name, view=None):
if not view:
@@ -133,7 +134,7 @@ def should_perform_action(name, view=None):
return name not in re.split(r'\s*,\s*', disabled_actions.strip())
-def should_handle_tab_key():
+def should_handle_tab_key(syntax=None):
view = active_view()
scopes = settings.get('disabled_single_snippet_for_scopes', None)
cur_scope = view.syntax_name(view.sel()[0].begin())
@@ -153,6 +154,13 @@ def should_handle_tab_key():
# hardcoded Lorem Ipsum generator
return True
+ # detect inline CSS
+ if syntax is None:
+ syntax = ctx.js().locals.pyGetSyntax();
+
+ if syntax == 'css':
+ return True
+
known_tags = settings.get('known_html_tags', '').split()
if abbr in known_tags or ctx.js().locals.pyHasSnippet(abbr):
return True
@@ -249,8 +257,8 @@ def run(self, edit, **kw):
class TabExpandHandler(sublime_plugin.EventListener):
- def correct_syntax(self, view):
- return view.match_selector( view.sel()[0].b, cmpl.EMMET_SCOPE )
+ def correct_syntax(self, view, syntax='html'):
+ return syntax == 'html' and view.match_selector( view.sel()[0].b, cmpl.EMMET_SCOPE )
def html_elements_attributes(self, view, prefix, pos):
tag = cmpl.find_tag_name(view, pos)
@@ -289,13 +297,17 @@ def on_query_context(self, view, key, op, operand, match_all):
if key != 'is_abbreviation':
return None
- if not check_context() or not should_handle_tab_key():
+ if not check_context():
+ return False;
+
+ syntax = ctx.js().locals.pyGetSyntax();
+ if not should_handle_tab_key(syntax):
return False
# 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.correct_syntax(view, syntax) and
self.completion_handler(view)):
return None
@@ -324,10 +336,13 @@ def on_query_completions(self, view, prefix, locations):
for p in completions:
l.append(('%s\t%s' % (p['k'], p['label']), p['v']))
+ if not l:
+ return []
+
return (l, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
- if ( not self.correct_syntax(view) or
- settings.get('disable_completions', False) ): return []
+ if not self.correct_syntax(view) or settings.get('disable_completions', False):
+ return []
handler = self.completion_handler(view)
if handler:
@@ -522,5 +537,5 @@ def run(self, edit, attribute=None, **kw):
class EmmetResetContext(sublime_plugin.TextCommand):
def run(self, edit, **kw):
- ctx.reset()
+ update_settings()
Oops, something went wrong.

0 comments on commit 1651c0f

Please sign in to comment.