JavaScript addicts

June 26, 2008

“Duplicate line/selection” macro for Komodo

Filed under: development tools — Tags: , , , , — Wolfram Kriesing @ 6:43 pm

I don’t remember which IDE it was that made me learn to use the shortcuts (may be Turbo Pascal back then), and (almost) since then I am too lazy to learn new shortcuts. Now I always first customize the keyboard shortcuts.
And already for a long time I am missing Ctrl+D/Apple+D for Komodo Edit which I use for editing JavaScript, CSS and HTML. This shortcut is supposed to duplicate either the current line or the entire selection. To make a long story short, here is the screencast video (1:04 min) that shows you how to apply the macro shown below.

Since there seems to be no native implementation of that in Komodo I just took some JavaScript skills and the time to look into the macro stuff, and found out that it is actually pretty easy. After looking at the macro API doc to find out how to differentiate if something is selected or not. It was as simple as recording the two macros and mixing them together, surrounded by an “if” that does the job right for the selection and the other for the current line. And I was done.

This is the end result. Just create a new macro and put the source there (the video shows how to do that in detail).


// Duplicate line/selection macro, more info at
// http://blog.uxebu.com/2008/06/26/duplicate-lineselection-macro-for-komodo/
komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };
if (ko.views.manager.currentView.scimoz.selText){
    // Copy the current selection
    komodo.doCommand('cmd_copy')
    komodo.doCommand('cmd_lineNext')
    komodo.doCommand('cmd_linePrevious')
    komodo.doCommand('cmd_paste')
} else {
    // Copy the current line
    komodo.doCommand('cmd_homeAbsolute')
    komodo.doCommand('cmd_selectLineNext')
    komodo.doCommand('cmd_copy')
    komodo.doCommand('cmd_paste')
    komodo.doCommand('cmd_paste')
    komodo.doCommand('cmd_linePrevious')
}

Have fun duplicating …

3 Comments »

  1. [Manual Trackback] :) How to enable this feature in Eclipse/Aptana: http://www.mahner.org/weblog/zeile-verdoppeln-eclipse/

    Comment by Martin — July 24, 2008 @ 2:52 pm

  2. [...] show anything about macros, I do use macros. I just honestly forgot about it, even though it was my very first blog entry here on our blog. The story behind simply is that I used this slide (to the right) three days ago [...]

    Pingback by Uxebu.com - JavaScript addicts » I do use Macros in Komodo — October 31, 2008 @ 10:04 pm

  3. Thanks a lot! I missed this feature after migrating to Komodo from Nuspere!
    BTW: Komodo itself has Duplicate LINE (but not SELECTION) feature, but it is insufficient for me.

    Comment by ThyBzi — December 3, 2008 @ 8:57 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Copyright 2008 - Uxebu, Ltd.
All Rights Reserved