What is the code used for command "Select Block (Ctrl + B)"?

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:


That will select the block in which your cursor is sitting.


  • Carey

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) {
    if(/['":\s]/gi.test(String.fromCharCode(scimoz.getCharAt(start)))) break;
while(end < scimoz.length) {
    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?


Hi @paulodetarso,

Could you be more specific about what you want to do? It’s not clear to me what your end goal is or what you’re trying to accomplish.

  • Carey

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…


Hmm have you tried the select block command yet? It does exactly that. If you do it in a PHP file it will select whatever code block you’re in.

function blah(){  /* selects from here */
    echo 'I really like pizza'; /*Run select block here*/
} /* to here */

Is that what you are looking for?

  • Carey

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.

If you’re interested, the original blockSelect code uses the marker folds logic to perform it’s task: https://github.com/Komodo/KomodoEdit/blob/master/src/editor/koLanguageCommandHandler.p.py#L963

  • Carey

Thanks @careyh! I don’t know if I’ll do what I want, because I just know JavaScript, not Python… I thought the code was available in both languages… :disappointed:

Well, I’ll try do something, thanks for your attention.


You can write it in Python or Javascript, it’s up to you :wink: 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 :smiley:

If you have issues while writing it feel free to post your code here and ask questions.

  • Carey