Hi people! I want to create a macro (JavaScript) similar to “Select Block” command, is it possible access the code that runs when you press “Ctrl + B”? I know some commands, but I would take some of the code that already exists and that is what I need…
Yep, this is totally possible. Komodo has a ton of “commands” under the hood. Select Block is one of them. You can open Commando (Ctrl + Shift O) and select the Command scope to see all of the available commands (they are also what you assign key bindings to in your preferences.
Any way, long story long, you’ll want a macro that has this line it it:
ko.commands.doCommand("cmd_blockSelect")
That will select the block in which your cursor is sitting.
Hello careyh, thanks for reply. But what I need is get the “real code executed” when Komodo performs the command “cmd_blockSelect”. For example, bellow he have a macro that open a file directly on editor, using a shortcut:
var scimoz = ko.views.manager.currentView.scimoz;
var start = scimoz.wordStartPosition(scimoz.currentPos, true);
var dir = ko.views.manager.currentView.koDoc.file.dirName;
var end = start;
while(start > 0) {
start--;
if(/['":\s]/gi.test(String.fromCharCode(scimoz.getCharAt(start)))) break;
}
while(end < scimoz.length) {
end++;
if(/['"?\s]/gi.test(String.fromCharCode(scimoz.getCharAt(end)))) break;
}
scimoz.anchor = (start + 1);
scimoz.currentPos = end;
fileToOpen = (scimoz.selText);
if(fileToOpen && fileToOpen.length > 0) {
ko.open.URI( ko.uriparse.pathToURI(dir + '/' + fileToOpen) );
}
So, what I want is get the code to change it as I need, is it possible?
When we execute the command “Select Block”, he works fine with HTML, but in my case, I would like to use same idea to select a piece of code, but with PHP, not with HTML. So I could change the code used by command “Select Block” and adapt it…
Humm… Almost this… When I run “Select Block”, using your example above, all the code between “function blah” and the last “}” is selected. What I want is that the code between “{” and “}”, “[” and “]” or “{” and “}” be selected, not including the “function” word or other parts that aren’t inside the desired area…
Ahhh well, that was the detail I was hoping for. It’s entirely possible to write a macro to do that. You could do a similar style search as you did in your code snippet and search for function scope between brackets.
Search backward until you find the first “{” then forward until you find a “}” that is the closing bracket for that scope level.
You can then assign a keybinding to the macro to run it at will or use Commando and select the macro from the Tools scope.
You can write it in Python or Javascript, it’s up to you I was just sharing the Komodo code just incase you were interested or wanted to have it guide you.
Your code you shared above would work quite well I think you just need to search for a different delimiter, eg “{” and “}”. I just had no idea what you wanted before or else I would have said that earlier
If you have issues while writing it feel free to post your code here and ask questions.