Komodo Edit archive

ko.eggs.boing()

2007-06-22 10:38

Deep in the bowels of the Komodo 4.1 documentation — more precisely the documentation for the JS API you’ll find documentation for the boing() method on the eggs object

So, what are you waiting for, create a macro with the following code:

ko.eggs.boing();

… and run it.

Three and a half years ago, I was as wrong as it's humanly possible to be

2007-06-05 23:15

Roughly three and a half years ago, I wrote a blog entry titled Why Linux has failed, and why Linux will fail again. Roughly two years ago, I switched — to the operating system I claimed had failed, and would fail again. Linux. Ubuntu to be precise.

Recently, Mark Pilgrim blogged about his first year with Linux and Sam Ruby followed up with his May 2005 switch.

So, what has my experience with Linux been, and how does it relate to my previous issues. Let’s reexamine what I wrote about Joe Phobic:

Joe has:

  • Never customized windows. Not even changed the default resolution.
  • Never touched the control panel.
  • Never used the command line.

During my 2005 switch, I:

  • Never had to customize Gnome itself. I made one customization to Nautilus, to prevent it from opening a new window for every folder I selected
  • Never touched the control panel, save perhaps from setting the screen saver, and resetting the resolution when I replaced a monitor
  • I did use the command line. But I was in no way forced to. I did so out of choice, and I did so to reconfigure X after I had rather royally hosed my own xorg.conf (but I’m not Joe Phobic, either).

… so it’s pretty safe to assume that my assumptions about whether Joe Phobic could handle this was wrong. Elaborating, saying something about what I didn’t write back then:

  • Ubuntu came preinstalled with all of the applications Joe would need. He could be as phobic as he wanted, because he had replacements for all of his applications
  • The cost of switching window manager to Gnome from Windows is for all practical purposes zero. He doesn’t have to relearn much, save for icon positions.
  • There’s more, I’ll get to that later.

Further, I wrote, while having spent some time on a system, trying to locate a simple calculator:

This is where Linux fails. Miserably. Linux is about freedom. A different kind of freedom. It’s freedom to choose to use any one of seven text editors to perform the same task. It’s the freedom to choose any one of several ridiculously complicated Window Managers. It’s the freedom to choose any one of two or three IDEs. It’s the freedom to install lots of perpetually unused servers.

… and, the money quote …

Windows is all about freedom. Windows is freedom from complicated choices, it’s freedom from having to learn something new, something not really relevant to the task you want to do.

I will spare you the pain (or amusement) of giving me an embarrasing reward for being silly: The undersigned is hereby awarded the price for “Most embararssing remark about operating systems, freedoms and choices”.

In July 2005, when I switched, I spent a full four to five hours getting a Windows 2000 system that hadn’t been booted for three months back into a usable state. I spent lots of time trying to kill update managers that caused nothing but network congestion and high CPU use. I spent time dismissing dialogs. I didn’t feel free then. Nor did I feel free the time before that, when I hosed my Windows registry, because I yanked an IDE cable from a running system. I learnt a lot about restoring, no make that finding various ways of failing to restore a system whose every copy of the shackles called the “Windows Registry” had gone missing in action.

Neither did I feel free when I, a year after switching my work machine over to Linux, tried booting it, because I needed a firmware update for my mobile phone. Updating this phone’s firmware required Flash to be installed, and it required MSIE to be the default browser. So, after having gone through roughly the same update dance as I went through with the Windows 2000 system, I thought resetting the browser to MSIE would be trivial. Not so. It took manually editing the registry. It took uninstalling every single third-party browser on the system. It involved downloading a shoddy third-party application. It took a lot of cursing. And I presume it also took luck to get this working. And some more cursing. And boy, did I feel free.

And I am free. Like Mark, I love apt, update-manager and its siblings to death. I don’t compile software (Ok, I’ve done it once, to get a CVS version of some spec-related tools working). I have exactly two applications that aren’t updated with the rest, Komodo Edit and Opera. And the latter one is by choice, because I run internal versions, and as such there is no point in me using the repository versions. That leaves it down to one application not automatically managed, updated, and taken care of. Across operating system upgrades. With all of the user data kept. I also (apart from a few text editor) have only one of each application, but they fill distinctly different needs, and I have all the software I need out of the box.

Linux has given me both freedom of choice, and freedom from choice. Windows never offered me “of”, and it only ever pretended to offer me “from”. On my personal computers, I only have Linux installed. I keep the XP partition on the work computer around, just in case. I don’t expect to boot it often, I hope I don’t have to boot it often.

Word count for HTML documents

2007-04-19 13:35

Ok, I’ll have to be careful, so this site doesn’t become a Komodo-only fansite, but I still feel the need to praise the exceptional value of this editor.

I’m currently busy preparing a paper. The thing is, however, that I have to produce an approximate number of words in this paper. Most people would’ve just say “use wc”. Normally, this is a good suggestion, but as the paper I’m writing is HTML, WC isn’t neccesarily accurate. It ends up counting elements surrounded by whitespace as “words”. Which is, according to the tool’s design, entirely correct. It’s correct, but not correct for me, so I needed to roll my own, and this is where Komodo comes in very handy:

Since Komodo is a XUL application, it also conveniently exposes a document object, which we can reuse for this purpose. See below, for a macro that may not qualify as ‘beautiful’, but it’s still extremely handy:

komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };
var text = (komodo.editor.selText || komodo.editor.text).replace(/<\?.*\?>/,"").replace(/<!.*>/,"");
var doc = document.createElementNS('http://www.w3.org/1999/xhtml','floble'); // implementation.createDocument('http://www.w3.org/1999/xhtml',null,null)
doc.innerHTML = text;
text = doc.textContent.replace(/^\s*/,'').replace(/\s*$/,'').replace(/\s{2,}/igm," ");
textNodes = text.split(/\s+/);
alert("Wordcount: "+textNodes.length);

So, you’re wondering what more you can do? Well, mostly anything you could ever think of doing in a browser.

Komodo: Open current selection as file

2007-03-22 17:33

When switching to Komodo Edit, I missed the ability to open file named by the current selection. Luckily, because of the macro support, getting this feature is fairly easy. This macro will re-enable that feature. It opens the current URL in the editor. If the URL appears to be relative, it lets Komodo resolve the URL, but it also supports absolute URIs and for absolute URL’s it has support for the file, http, ftp and scp protocols. If there is no current selection, you will get prompted to type a URL (this is a deliberate choice, because if I want to browse for a document, I can use the regular Open dialog).

So, how do you get this? Create a JavaScript macro with the following contents, and bind it to your favorite key (mine is Ctrl-Alt-O):

try {
    komodo.assertMacroVersion(2);
    if (komodo.view) { komodo.view.setFocus() };
    var sel = komodo.editor.selText;
    if (!sel.length)
    {
      sel = prompt("Choose filename");
    }
    // resolve path if not absolute
    var re = new RegExp("^(\/|(file|http|ftp|scp):\/\/)");
    if (!re.test(sel))
    {
      var dir = komodo.document.displayPath.replace(komodo.document.file.baseName,'');
      sel = dir+sel;
    }
    else
    {
      var re = /^((http|ftp|scp):\/\/[^\/]+)/;
      if ((sel[0] == "/") && (re.test(komodo.document.displayPath) ))
      {
         var matches = re.exec(komodo.document.displayPath);
         if (matches[1])
         {
            sel = matches[1]+sel;
         }
      }
    }
    komodo.openURI(sel);
}
catch(e)
{
    alert(e)
}

Edit: Small fix to make relative URI’s work properly on remote files.

Komodo Edit add-ons

2007-03-20 16:26

Since making the switch to Komodo Edit, I’ve made a few customizations to it, to make my day-to-day editing of markup a bit easier. The files are available through SVN. Documentation follows.