Welcome, guest | Sign In | My Account | Store | Cart

In Emacs I used to use find-alternate-file all the time to replace the current buffer with a different one, usually one in the same directory. Komodo doesn't provide an off-the-shelf way to do this, and if you can't be bothered to close buffers when you no longer need them, you'll soon suffer from the dreaded tab buildup problem, up there with the heartbreak of browser tab overload. But it's easy to write a macro to avoid this.

JavaScript, 13 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
var view = ko.views.manager.currentView;
var file = view.document.file;
var path = ko.filepicker.browseForFile(file.dirName,
                                        file.baseName,
                                        "file to replace");
if (!path) return;
ko.views.manager.doFileOpenAsync(path, 'editor', null, -1,
    function(newView) {
        if (newView) {
            view.close();
            newView.makeCurrent();
        }
    });

It's tempting to assign this macro the keybinding "Ctrl-K Ctrl-V", but on IDE that's the default binding for [SCC | Revert]. Note that the use of the callback let's us accomplish two tasks: first, we only close the old buffer if we succeeded at opening the new one. And second, the Async callback lets Komodo open the file asynchronously, and continue the operation only when it's ready.

2 comments

Sridhar Ratnakumar 13 years, 7 months ago  # | flag

Just curious: is it possible to get the "last accessed" time of any tab via the Komodo API? If yes, it would be interesting to write macro that closes all tabs older than one day. Currently I use "srid's stuff/Close All" macro.

Eric Promislow (author) 13 years, 7 months ago  # | flag

Not that I know of, but you can tack one on with a startup macro:

window.addEventListener('current_view_changed', function(event) { ko.views.manager.currentView['extaccessTime'] = new Date().valueOf() }, false);

This tracks when you bring up a file, but it doesn't track modifications to it. You can do those by doing something like

view.addModifiedHandler(function() { view['*ext*accessTime'] = new Date().valueOf(); },
                         null, Components.interfaces.ISciMoz.SC_MOD_INSERTTEXT)

but I imagine this would be a bit more expensive than the first way.

Created by Eric Promislow on Tue, 28 Sep 2010 (MIT)
JavaScript recipes (69)
Eric Promislow's recipes (11)

Required Modules

  • (none specified)

Other Information and Tasks