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

This script will add real auto-wrap functionality to Komodo, ie. it will wrap text after reaching column 80 just in the same way as you would by pressing <Enter>.

You can bind a keyboard shortcut to macro, or trigger it on Komodo startup, or both. Either way, repeated pressing of binded shortcut (or running the macro) will switch it off and on again.

In fact, script only adds event listener, which fires a function (after each keypress), that checks if cursor position is not in column higher that 79 and, if needed, calls Komodo built-in function "Reflow paragraph" to reflow the paragraph.

This recipe was not created by me from scratch. I have just read David Brewer's feature request at komodo-discuss, used troyt's original code for autowrap and tweaked/simplified it a little.

JavaScript, 24 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (typeof (mymacros) == "undefined") {
  mymacros = {};
  mymacros.started = false;
  mymacros.autoReflow = function (event) {
    // stop if using Undo/Redo - it will not function properly
    var ch = (String.fromCharCode(event.charCode)).toLowerCase();
    if (event.ctrlKey && (ch == 'z' || ch == 'y'))
      return;
    
    var scimoz = ko.views.manager.currentView.scimoz;
    if (scimoz.getColumn(scimoz.currentPos) > 79) {
      ko.commands.doCommand("cmd_editReflow");
    }
  } 
}

if (!mymacros.started) {
  mymacros.started = true;
  window.addEventListener("keypress", mymacros.autoReflow, true);
}
else {
  mymacros.started = false;
  window.removeEventListener("keypress", mymacros.autoReflow, true);
}

Troyt's original code has one minor annoyance: when I used Ctrl+Z or Ctrl+Y (for Undo/Redo functions), script sometimes stopped these functions from working properly, because it was repeatedly reflowing paragraph. That's why I add this little check for these keys in my script:

var ch = (String.fromCharCode(event.charCode)).toLowerCase();
if (event.ctrlKey && (ch == 'z' || ch == 'y'))
  return;

This way, script will not reflow paragraph if it sees Ctrl+Z(Y).

Created by Furlo on Sun, 8 Apr 2012 (MIT)
JavaScript recipes (69)
Furlo's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks