Welcome, guest | Sign In | My Account | Store | Cart

A simple Macro that wraps the current selection in a code block supplied by the requested snippet.

JavaScript, 14 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
var view = ko.views.manager.currentView;
var scimoz = view.scimoz;

var snippet_name = ko.dialogs.prompt('Enter a wrapper snippet name');

if (snippet_name && snippet_name.length > 0) {
  var snpt = ko.abbrev.findAbbrevSnippet(snippet_name);

  if (!/\[\[%(s|w|S|W)\]\]/.test(snpt.value)) {
    ko.dialogs.alert('FAIL: no selection / word under cursor interpolation in this snippet! Are you sure this is is a \'wrapper snippet\'?');
  } else {
    ko.abbrev.insertAbbrevSnippet(snpt);
  }
}
  1. add the macro to your toolbox, call it 'wdiv' and bind it to a key combination.
  2. create an html snippet like '<div>[%s]</div>' and remember to set it to honour the current indentation.
  3. open an html page, select something and hit the key-binding
  4. in the prompt, type in 'wdiv'
  5. Profit!

I have created a bunch of 'wrapper snippets' in my toolbox that allow me to wrap the current selected text in things like try/catch, if/else, html blocks, function, etc.