Hi. Is it possible to make selected text to wrap when I call symbols like ", ', [, {, (, `? SublimeText style. Last symbol would be useful for SQL. I have to insert quotes and brackets manually so often, it became a rutine.
Also, usually when I press some quote, it doubles automaticaly. But when I do it inside of string, it’s not. Example - quote after = will not double when you call it:
$query = mysql_query("SELECT `user_id` FROM `wp_loans` WHERE `some_text`='test'");
Same stuff with iverted quotes - " will not double:
Not natively possible (I’d be interested in adding it but afraid that it might confuse people). Easily doable as a macro though; I went ahead and took the liberty:
/**
* @fileoverview Automatically adds quotes around selection when selecting
* text and pressing single/double quote
* @author Nathan Rijksen
* @version 0.1
*/
if (typeof(extensions) === 'undefined')
extensions = {};
if (extensions.AutoQuotes && extensions.AutoQuotes.onKeyPress) {
// Remove the existing trigger handler, we'll re-instate it.
var editor_pane = ko.views.manager.topView;
editor_pane.removeEventListener('keypress', extensions.AutoQuotes.onKeyPress, true);
}
extensions.AutoQuotes = {};
(function() {
var charCodes = [39, 34, 91, 93, 123, 125, 40, 41];
this.onKeyPress = function(e) {
if (charCodes.indexOf(e.charCode) == -1) return;
var strLeft = strRight = String.fromCharCode(e.charCode);
if (strLeft == '(') strRight = ')';
else if (strRight == ')') strLeft = '(';
else if (strLeft == '[') strRight = ']';
else if (strRight == ']') strLeft = '[';
else if (strLeft == '{') strRight = '}';
else if (strRight == '}') strLeft = '{';
// Get scimoz API
var editor = ko.views.manager.currentView.scimoz;
if ( ! editor || editor.selText == "") return;
// Prepare our auto-completion
var fakeSnippet = {
hasAttribute: function(name) {
return name in this;
},
getStringAttribute: function(name) {
return this[name];
},
name: "autoquote snippet",
value: strLeft + "[[%w]]" + strRight
};
// Insert auto-completion
ko.projects.snippetInsert(fakeSnippet);
// Prevent default auto-completion
e.preventDefault();
return false;
}
// Bind keypress listener
var editor_pane = ko.views.manager.topView;
editor_pane.addEventListener('keypress', this.onKeyPress, true);
}).apply(extensions.AutoQuotes);
Add to your toolbox, set to run on startup and run the macro. Now pressing ’ or " while having text selected will wrap it with those characters.
This is a GREAT feature. I am forever needing to wrap code examples with backticks in Markdwon, or put quotes around strings I’ve typed out but forgotten to put quotes around.
But there’s a fly in the ointment. It only works for the simplest of cases. It doesn’t work if there are any punctuation characters in the text to be wrapped.
WORKS
Fabulous
Good ship Lollypop
counter[error] += 1 # for the “error” index
I always used Komodo IDE and Sublime Text, I always edit my codes in sublime then move it to komodo, but lately Komodo IDE is turning into a really good text editor.