@Thorsten-Heuer , @fml2 , @PeterJones :
I made a simple plugin to do this, which you can find here:
https://github.com/Coises/Marginalize/
There is a limitation to this method of wrapping. This is true whether you drag the window edge, open a panel or use a script or a plugin:
In most contexts, such as in a browser, soft wrapping replaces a space with a new line when breaking between words. When Scintilla wraps plain text at a space, the space is still included on the line before the wrap. So a word that should fit exactly to the margin will be pushed to the next line instead, because there isn’t room for the space.
When a language other than “None (Normal Text)” is in effect, spaces can be pushed to the beginning of a line. (I think what happens is that lines can wrap at any point where the style changes, but I haven’t verified that.)
Either way, you will not get exactly what soft wrapping normally is, because Scintilla always displays spaces somewhere when wrapping on a space.
Like @PeterJones, I was surprised to find that SCN_UPDATEUI isn’t issued when the window is resized… but not too surprised, since I had already come across another situation, zooming, where you would expect it to trigger, but it doesn’t.
So at first I tried trapping SCN_UPDATEUI and SCN_ZOOM and also subclassing the two Scintilla controls to watch for WM_SIZE messages. I wondered, though, what else might not be included in SCN_UPDATEUI that I didn’t know. I decided that, at least working in C++, there was no obvious advantage to avoiding SCN_PAINTED, which I think is bound to catch everything that matters, without getting into subclassing. Note that SCN_UPDATEUI itself is called quite often, too — I’m not really sure how much worse SCN_PAINTED can be than SCN_UPDATEUI plus a hook or a subclass.
It appears that setting the margins can at least sometimes cause a repaint even when the new margins are the same as the old. In any case, I found it necessary to be especially careful that a window too narrow to allow for the specified width didn’t create some very strange artifacts by repeatedly setting the margins to zero when they already were zero.