Automatically reflow long lines while typing

Hello,

I’m, wondering if there is a way to automatically break long lines into
multiple lines while you are typing (is it called code reflowing?). I’ve
checked there is an auto-wrap feature in ‘preferences > smart
editing’ and a code reflow action in ‘code’ menu. Is there a way to do
this while you are typing? Let’s say I’m writing a long line: as soon as I
get to 80 columns can the editor insert a line break and take me to an
indented new line?

Thanks for you help!

1 Like

Hi there, you can reflow a paragraph of text via Code > Reflow Paragraph. This is not done automatically while you type, though it wouldn’t be very difficult to invoke it through a macro automatically if you’d wish that.

Note that this feature is intended for plain text, it will not intelligently identify where to end a line (and escape it) for your languages. Personally I prefer to do this myself and I use the edge line column (Prefs > Editor > Smart Editing) to help me with this.

Here are a couple of macros that can do this. I call them “start-auto-rewrap” and “auto-rewrap-end” (just to be inconsistent for fun), because I don’t always want autowrap on, like when typing code.

Here’s the macro to kick in autowrap:

// Komodo macro for automatic reflowing of paragraphs
ko.views.manager.currentView.scintilla.focus();
ko.autoReflow = function (event) {
  var currentView = ko.views.manager.currentView;
  var scimoz = currentView.scimoz;
  var myEdge = gPrefs.getLongPref("editAutoWrapColumn");
  if (scimoz.getColumn(scimoz.currentPos) > myEdge) {
    ko.commands.doCommand('cmd_editReflow');
  }
}
ko.views.manager.topView.addEventListener("keypress", ko.autoReflow, true);

And here’s the macro to end it:

// Komodo macro to stop the autoReflow keypress listener
var topView = ko.views.manager.topView;
topView.removeEventListener("keypress", ko.autoReflow, true)

Somewhere in the blog archives there’s a post by TroyT on how to make the bell ring when the line nears the autowrap-column point, just like an old-timey typewriter.

  • Eric
2 Likes

Haha that is awesome, I just had to find it - Revenge of the auto-wrap (type type type DING!) - ActiveState

I personally had no interest in using this macro myself – until now… :slight_smile:

Thank you for your help! I’ve tried the macro, it works fine!
I came across that blog post before, but I was wondering if there was a built-in system to do so. In fact I’m required to stick to PEP8 specifications and it would be very nice if there was some tool to help you keeping code up to those standards while you type. Maybe it could be a hint for a future feature :smile:
As nathan​r says the macro (as well as ‘code reflow’ action) is not language-aware, but it still helps :smile: