Created
May 7, 2014 17:39
-
-
Save Naatan/e82011550823421e7013 to your computer and use it in GitHub Desktop.
Komodo IDE - Auto Braces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileoverview Auto completes curly braces to start on a new line - experimental | |
* @author Nathan Rijksen | |
* @version 0.1 | |
*/ | |
/** | |
* Komodo Extensions Namespace. | |
* This namespace was suggested by JeffG. More information is available at: | |
* {@link http://community.activestate.com/forum-topic/extension-s-namespace} | |
* | |
* @type Object | |
*/ | |
if (typeof(extensions) === 'undefined') | |
extensions = {}; | |
if (extensions.AutoBraces && extensions.AutoBraces.onKeyPress) { | |
// Remove the existing trigger handler, we'll re-instate it. | |
var editor_pane = ko.views.manager.topView; | |
editor_pane.removeEventListener('keypress', extensions.AutoBraces.onKeyPress, true); | |
} | |
extensions.AutoBraces = {}; | |
(function() { | |
this.onKeyPress = function(e) { | |
if (e.charCode != 123 /* { */ || !e.shiftKey) return; | |
// Get scimoz API | |
var view = ko.views.manager.currentView; | |
var editor = view.scimoz; | |
if ( ! editor) return; | |
// Validate our context | |
var currentPos = editor.currentPos; | |
var strRight = editor.getTextRange(currentPos, currentPos + 1); | |
if ([0,10].indexOf(strRight.charCodeAt(0))===-1) return; | |
// Prepare our auto-completion | |
var fakeSnippet = { | |
hasAttribute: function(name) { | |
return name in this; | |
}, | |
getStringAttribute: function(name) { | |
return this[name]; | |
}, | |
name: "autobrace snippet", | |
indent_relative: "true", | |
value: "\n{\n [[%tabstop:]]\n}" | |
}; | |
// Insert auto-completion | |
ko.projects.snippetInsert(fakeSnippet); | |
// Prevent default auto-completion | |
e.preventDefault(); | |
} | |
// Bind keypress listener | |
var editor_pane = ko.views.manager.topView; | |
editor_pane.addEventListener('keypress', this.onKeyPress, true); | |
}).apply(extensions.AutoBraces); |
Dunno, they're adding all sorts of fancy things. Devmo might have something. I think they recommend that you use an unimplemented API, or something silly like that.... 😞
Damn for a second there I thought Devmo was some fancy new API.
value: "\n{\n [[%tabstop:]]\n}"
: as you can see - space instead of tab. I think value: "\n{\n\t[[%tabstop:]]\n}"
is more logical.
It's not meant to put a tab, ko.projects.snippetInsert will take care of that as per your preferences.
Note to those who prefer 1TBS curlies, use the following:
value: " {\n [[%tabstop:]]\n}"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hrm good point, any higher level API we can tunnel that through?