Skip to content

Commit 9f0e280

Browse files
committed
Adding automagic snippet from text.
1 parent 407d02c commit 9f0e280

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This is a collection of useful Komodo macros.
99
- [PHPDoc and JSDoc](#phpdoc-and-jsdoc)
1010
- [Incremental Numbering](#incremental-numbering)
1111
- [Copy Find Results](#copy-find-results)
12+
- [Automagic Snippets From Text](#automagic-snippets-from-text)
1213
- [How to Install](#installing)
1314
- [Contributing](#contributing)
1415

@@ -46,6 +47,13 @@ There can be two find results pane opened - this only works on the first one.
4647

4748
See the [code](find_results_copy.js).
4849

50+
### Automagic Snippets From Text
51+
52+
Create a snippet from selected text, add a name and automatically open properties
53+
to add keybinding.
54+
55+
See the [code](automagic_snippets_from_text.js).
56+
4957
## Installing
5058

5159
Create a new macro in your Komodo toolbox and copy/paste the contents into the

automagic_snippets_from_text.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Create a base snippet with the selected text
2+
scimoz = ko.views.manager.currentView.scimoz;
3+
var snip =
4+
ko.projects.addSnippetFromText(scimoz.selText);
5+
//create a date to be used as a unique name on the snippet
6+
var d = new Date();
7+
// Create a unique default name string
8+
var defaultName = "New Snippet - " + d.toLocaleTimeString().substr(0,8).trim()
9+
// Ask for a name or provide the unique default
10+
var name = ko.interpolate.interpolateStrings("%(ask:Snippet Name: " +
11+
defaultName + ")")
12+
// Assign the name to the snippet name attribute
13+
snip.name = name;
14+
// Open the snippet options to set a keybinding
15+
ko.projects.snippetProperties(snip);

0 commit comments

Comments
 (0)