View Full Version : Jump to last saved file

I would like to propose a new addition to already wonderful functions of:

Go back one location
Go forward one location
General: Most Recently Viewed File

which would be: Jump to last saved file
Usually in my workflow I have dozens of files that are open for reference and copy-from jobs, practically making their usage read-only, while there is always one file where I'm working on, which gets saved every once in a while. So, a function like that would help me always jump back to the file I'm pasting to, since that one would always be the last one saved.
I was informed that this could be achieved with a macro, but I have no idea where to start.
Any help on building such a macro would be greatly appreciated.

You could also use the Switch to Tab #1 command. Open commando (ctrl + shift + o), hit the command scope then search Switch. ALL of those commands can be mapped to a keybinding in your preferences. So that's probably the easiest route but it will require that said file stay in one spot. Easy enough if you just leave it in position 1.
This should be easy enough in a macro as well. You'll want the Komodo Extension Developer (http://komodoide.com/packages/addons/komodo-developer-extension/) for the Javascript shell.
Once you've got that you'll want the require("ko/views") SDK. Soon you'll be able to reference it online in the new Komodo docs (http://beta.docs.komodoide.com/SDK/api/commonjs) but that won't be updated until 9.3 release. For now you can tab through results in the JS shell. eg. require("ko/views").|//press tab twice at the bar. Note a view is the entire editor Mozilla UI element which wraps a the file object inside itself as koDoc.
Some functions you'll be interested in.
- To get all open file objects:
require("ko/views").all(); //returns an array
var view1 = require("ko/views").all()[0];

Get current view:


Once you have a view, get it's path:

var view = require("ko/views").current().get();

Get the views filename:

// filename.pyThat should get you started. There are MANY functions wrapped up in there so have a look and please do ask questions.
Oh one last function you'll want: view.focus() //http://forum.komodoide.com/images/emoji/apple/wink.png?v=0


Here's a simple userscript (macro) I quickly threw together:
if (extensions.goToLastSaved)
window.removeEventListener("file_saved", extensions.goToLastSaved.onFileSave);

(function() {

var lastView = null;

this.onFileSave = function()
lastView = ko.views.manager.currentView;

this.onGoto = function()
var v = ko.views.manager.currentView;
if (lastView && v != lastView)
xtk.domutils.fireEvent(lastView.parentNode._tab, 'click');

require("ko/commands").register("goto_lastsaved", this.onGoto, {label: "Go to Last Saved"});
window.addEventListener("file_saved", extensions.goToLastSaved.onFileSave);


Mark C.Smith
They compliment each other! Excellent!