Update: 22 April 2023 – Komodo Edit isn’t easy to find, but it’s still available. Check here. Most people prefer to use Komodo IDE, formerly a commercial software is now available at no cost. I like them both, but I think I like Komodo Edit better. I like other more full-featured IDE’s better than Komodo IDE.
Use the following javascript code to manipulate the JavaScript Macro API of ActiveState’s Komodo Edit / Komodo IDE advanced text editor/ Integrated Development Environment.
NOTE: To preserve sanity of those not wishing to scroll beyond Source Code
stuffs, I have instantiated the WordPress option, known to WP admins as <!–more–>, here. What does this mean? Look at top or bottom of this post (web log theme, dependent), for something which reads “More…”, or “Continue Reading…”, or something of the notion.
try { var bufferPath, selectedText, osPath, concatPath; bufferPath = ko.views.manager.currentView.koDoc.file.dirName; selectedText = ko.views.manager.currentView.scimoz.selText; osPath = Components.classes["@activestate.com/koOsPath;1"].getService(Components.interfaces.koIOsPath); concatPath = osPath.join(bufferPath, selectedText); if (!osPath.exists(concatPath)) { concatPath = osPath.join(osPath.dirname(bufferPath), selectedText); if (!osPath.exists(concatPath)) { ko.dialogs.alert("Can't find file " + selectedText); return; } } ko.open.URI(concatPath); } catch(e){ ko.dialogs.alert("error in macro: " + e); }
Further Instructions:
To use the “Open Selection” Macro in your own Komodo Editor, simply create a New Macro in the Toolbox, select JavaScript (vs Python) as the Macro API interpretor, and copy/ paste the following code in the Macro source code area, finally providing a proper title such as ‘Open Selected’ (i.e. for replacing the default, “New Macro”). The new Macro will appear in the Toolbox, identifiable by its custom title.
And Now, the Testies:
Test the macro: load a file which references other files, such as in PHP require/include functions. Select the portion of the code (eg. ‘includes/filename.php’) which points to an external file. While the selection is active, double-click the new macro. The file referenced in the selected text will open in a new tab within the existing Komodo Editor window. The macro provides a convenient enhancement to programming from the Komodo Edit environment.
Dig a Bit o’ Background Info, “yo”!
As an occasional user of KomodoEdit, the Open Source (aka. Open Komodo) text editor based on the commercial ActiveState product, Komodo IDE, I found myself intrigued with the advent of the JavaScript Macro API for Komodo. What is intriguing to me is the use of JavaScript, outside of the scope of web development; using JavaScript to manipulate HTML documents served via HTTP.
Dare to do DIFF!
.js Scripting: Out of Context of HTTP & HTML DOM!
Wha…?!
Neither the first, nor the only instance where JavaScript is used outside of the HTML DOM, I recognized the ActiveState Komodo JavaScript Macro API as a practical opportunity to experiment with JavaScript outside of the HTML DOM. Using only the distributed documentation, and my own creative ingenuity, I developed the following macro to interact with web project documents as edited within Komodo Edit.
Similar Solution: Different Editor
Elsewhere in WordPress Center .net, I presented a similar solution for the popular text editor
Notepad++, a Scintilla-powered editor developed for Windows systems. The following solution is quite different, as it requires knowledge; some skill in programming the functional language, JavaScript. Additionally, successful manipulation of the Komodo JavaScript Macro API requires knowledge beyond that native to JavaScript, as is detailed in the Komodo JavaScript Macro API manual. Knowing what I wanted to achieve (eg. open file as indicated in the selected text at the cursor), I arrived at the following through trial and error, and feedback from the ActiveState Komodo Community.
Enjoy!
I say enjoy the hell out of it, pally, lest we come a-lookin’ for you’s!
(heh heh. a little Philly-humor ne’r hurt nobody none, now did it? Enjoy it, or don’t. Who cares, right?)
Leave a Reply