Permalink
Browse files

Small improvements

  • Loading branch information...
1 parent 4240764 commit 1435e89448c7af97cccb181f3287b2c03dee501a @sergeche committed Nov 12, 2012
Showing with 76 additions and 17 deletions.
  1. +1 −1 Emmet.sublime-settings
  2. +13 −3 editor.js
  3. +3 −0 emmet-plugin.py
  4. +59 −13 emmet/emmet-app.js
View
2 Emmet.sublime-settings
@@ -23,7 +23,7 @@
// List of HTML and XML scopes where Enter key should insert formatted
// (e.g. with indentation) line break
- "formatted_linebreak_scopes": "meta.scope.between-tag-pair.html, meta.scope.between-tag-pair.xml, punctuation.definition.tag.end.html",
+ "formatted_linebreak_scopes": "meta.scope.between-tag-pair.html, meta.scope.between-tag-pair.xml",
// A comma-separated list of disabled action names.
// Listed action will not be triggered by default keyboard
View
16 editor.js
@@ -134,7 +134,9 @@ function pyPreprocessText(value) {
var zeroBase = 0;
var lastZero = null;
var range = require('range');
- value = require('tabStops').processText(value, {
+ var ts = require('tabStops');
+
+ var tabstopOptions = {
tabstop: function(data) {
var group = parseInt(data.group, 10);
var isZero = group === 0;
@@ -143,7 +145,13 @@ function pyPreprocessText(value) {
else
group += base;
- var result = '${' + group + (data.placeholder ? ':' + data.placeholder : '') + '}';
+ var placeholder = data.placeholder;
+ if (placeholder) {
+ // recursively update nested tabstops
+ placeholder = ts.processText(placeholder, tabstopOptions);
+ }
+
+ var result = '${' + group + (placeholder ? ':' + placeholder : '') + '}';
if (isZero) {
lastZero = range.create(data.start, result);
@@ -162,7 +170,9 @@ function pyPreprocessText(value) {
return ch;
}
- });
+ };
+
+ value = ts.processText(value, tabstopOptions);
if (lastZero) {
value = require('utils').replaceSubstring(value, '$0', lastZero);
View
3 emmet-plugin.py
@@ -460,6 +460,9 @@ def run(self, edit, **kw):
snippet = '\n${0}'
+ if len(view.sel()) > 1:
+ return view.run_command('insert_snippet', {'contents': snippet})
+
# let's see if we have to insert formatted linebreak
caret_pos = view.sel()[0].begin()
scope = view.syntax_name(caret_pos)
View
72 emmet/emmet-app.js
@@ -5790,20 +5790,26 @@ emmet.define('tabStops', function(require, _) {
var maxNum = 0;
var tabstops = require('tabStops');
var utils = require('utils');
-
- // upgrade tabstops
+
var tsOptions = {
tabstop: function(data) {
var group = parseInt(data.group);
if (group == 0)
return '${0}';
- if (group > maxNum) maxNum = group;
- if (data.placeholder)
- return '${' + (group + tabstopIndex) + ':' + data.placeholder + '}';
+ if (group > maxNum) maxNum = group;
+ if (data.placeholder) {
+ // respect nested placeholders
+ var ix = group + tabstopIndex;
+ var placeholder = tabstops.processText(data.placeholder, tsOptions);
+ return '${' + ix + ':' + placeholder + '}';
} else {
+ return '${' + (group + tabstopIndex) + '}';
}
- }
+ }
+ };
+
+ // upgrade tabstops
text = tabstops.processText(text, tsOptions);
// resolve variables
@@ -5958,16 +5964,21 @@ emmet.define('tabStops', function(require, _) {
start: buf.length,
name: m[1],
token: stream.current()
- });
+ });
} else if (m = stream.match(/^\{([0-9]+)(:.+?)?\}/, false)) {
+ // ${N:value} or ${N} placeholder
+ // parse placeholder, including nested ones
+ stream.skipToPair('{', '}');
var obj = {
start: buf.length,
group: m[1],
token: stream.current()
};
-
- if (m[2]) {
+
+ var placeholder = obj.token.substring(obj.group.length + 2, obj.token.length - 1);
+
+ if (placeholder) {
obj.placeholder = placeholder.substr(1);
}
@@ -7737,8 +7748,26 @@ emmet.define('expandAbbreviation', function(require, _) {
* @param {String} syntax Syntax type (html, css, etc.)
* @param {String} profile Output profile name (html, xml, xhtml)
*/
- actions.add('expand_abbreviation_with_tab', function(editor, syntax, profile) {
- if (!actions.run('expand_abbreviation', editor, syntax, profile))
+ actions.add('expand_abbreviation_with_tab', function(editor, syntax, profile) {
+ // do nothing if there is a selection
+ var sel = !!editor.getSelection();
+ var indent = require('resources').getVariable('indentation');
+// TODO create indentation
+// if (sel) {
+// // create a proper indentation, if there’s a selection that
+// // spans multiple lines
+// if (/[\r\n]/.test(sel)) {
+// var info = require('editorUtils').outputInfo(editor, syntax);
+// var selRange = require('range').create(editor.getSelectionRange());
+//
+// }
+//
+// return;
+// }
+
+
+ if (sel || !actions.run('expand_abbreviation', editor, syntax, profile)) {
+ editor.replaceContent(indent, editor.getCaretPos());
}
}, {hidden: true});
@@ -12158,6 +12187,9 @@ emmet.define('bootstrap', function(require, _) {
* of each file.
* This method requires a <code>file</code> module of <code>IEmmetFile</code>
* interface to be implemented.
+ * @memberOf bootstrap
+ */
+ loadExtensions: function(fileList) {
var file = require('file');
var payload = {};
var utils = require('utils');
@@ -12169,10 +12201,24 @@ emmet.define('bootstrap', function(require, _) {
try {
eval(file.read(f));
} catch (e) {
- emmet.log('Unable to eval "' + f + '" file: '+ e);
+ emmet.log('Unable to eval "' + f + '" file: '+ e);
+ }
+ break;
+ case 'json':
+ var fileName = getFileName(f).toLowerCase().replace(/\.json$/, '');
+ if (/^snippets/.test(fileName)) {
+ if (fileName === 'snippets') {
+ // data in snippets.json is more important to user
+ userSnippets = this.parseJSON(file.read(f));
+ } else {
+ payload.snippets = utils.deepMerge(payload.snippets || {}, this.parseJSON(file.read(f)));
}
} else {
- case 'json':
+ payload[fileName] = file.read(f);
+ }
+
+ break;
+ }
}, this);
if (userSnippets) {

0 comments on commit 1435e89

Please sign in to comment.