Page 1 of 3
Automatic splitting code across lines...
Posted: Thu Jan 03, 2008 12:13 pm
by DoubleDutch
WARNING: This is an experimental editor patch, it may have unpredictable results (you may lose work) !!!
I pinched a tip on how to get messages to the PureBasic editor by netmaestro (
http://www.purebasic.fr/english/viewtopic.php?t=30379 ).
Compile this code to "EditorWrap.exe" and make it a PureBasic tool.
Code: Select all
scintilla = Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
If scintilla
SendMessage_(scintilla,#SCI_SETHSCROLLBAR,#False,0)
SendMessage_(scintilla,#SCI_SETWRAPMODE,#True,0)
SendMessage_(scintilla,#SCI_SETWRAPVISUALFLAGS,#SC_WRAPVISUALFLAG_START,0)
SendMessage_(scintilla,#SCI_SETWRAPSTARTINDENT,16,0) ; <-- indent amount
EndIf
End
then compile this code to "EditorNoWrap.exe" and also make it a PureBasic tool.
Code: Select all
scintilla = Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
If scintilla
SendMessage_(scintilla,#SCI_SETHSCROLLBAR,#True,0)
SendMessage_(scintilla,#SCI_SETWRAPMODE,#False,0)
EndIf
End
To turn on the line splitting, just click start the EditorWrap tool, to stop use the EditorNoWrap tool. On vista you may have to compile with the user mode flag on?
I did a bit of testing (2 minutes!) and it appears to work ok.
FINAL WARNING: This is an experimental editor patch, it may have unpredictable results (you may lose work) !!!
EDIT: SEE BELOW FOR AN UPDATED VERSION!!!
Re: Automatic splitting code across lines...
Posted: Thu Jan 03, 2008 12:42 pm
by PB
Good one!

Seems to work fine so far, but I've backed up my sources!
Tip: I've got it set to trigger on "Sourcecode loaded" so it's automatic.

This tip may
finally end all those line continuation / multiline code requests.

Posted: Thu Jan 03, 2008 12:45 pm
by DoubleDutch
Glad you like it.
Please be careful with it though, it would really be best if Freak/Fred took a look at it to make sure it's safe.
Posted: Thu Jan 03, 2008 12:51 pm
by PB
> best if Freak/Fred took a look at it to make sure it's safe
If they do, and agree that it's 100% safe, then it should become an IDE preference.
Posted: Thu Jan 03, 2008 12:54 pm
by DoubleDutch
I agree that would be the best solution.
Re: Automatic splitting code across lines...
Posted: Thu Jan 03, 2008 2:06 pm
by PB
Here's how I've modified your code for use in my IDE. It's a single tool entry
that I've set to a hotkey of Alt+W, and it toggles the wrapping for me when
I need it.

(Note: You don't need to set or remove the horizontal scrollbar
because the #SCI_SETWRAPMODE call does it automatically).
Code: Select all
ide=Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
If ide
SendMessage_(ide,#SCI_SETWRAPMODE,1-SendMessage_(ide,#SCI_GETWRAPMODE,0,0),0)
EndIf
Posted: Thu Jan 03, 2008 2:32 pm
by DoubleDutch
Nice mod.
I wasn't too sure about the hscroll, so I just shoved it in anyhow.
What about the indent of 1 though and the indicator being at the back? (or is the default at the front?)
So you have also encountered no problems, it looks like it's a stable hack.
Posted: Thu Jan 03, 2008 2:48 pm
by PB
> What about the indent of 1 though and the indicator being at the back?
The indent of 1 can be removed (I did it temporarily) but I preferred to see
the line continuation character, by setting this:
Code: Select all
SendMessage_(ide,#SCI_SETWRAPVISUALFLAGS,#SC_WRAPVISUALFLAG_START,1)
That puts it at the start of each indented line. I also didn't set any indent like 16.
The only thing is, the character seems to be black in color with no obvious way
of changing it, so I've had to lose my black IDE background.
> So you have also encountered no problems
None yet.

Even pressing the End key at the start of a wrapped line will jump
to the end of the line(s) below, as it should. Seems mighty fine to me.
Posted: Thu Jan 03, 2008 2:55 pm
by DoubleDutch
The indicator may have a style? I'll see if I can find it, if not I'll post a request on the official Scintilla list.
Edit: Not found a way of changing the colour using a command, so I've posted to the Scintilla list.
Posted: Thu Jan 03, 2008 4:01 pm
by MrMat
It uses STYLE_DEFAULT. You can also override it with SCI_SETWHITESPACEFORE but i think that is for backwards compatibilty.
Posted: Thu Jan 03, 2008 4:08 pm
by DoubleDutch
Thanks.
Looks like the message isn't depreciated so it should be ok to use.
Posted: Thu Jan 03, 2008 4:13 pm
by Berikco
Works fine here.
No problem whatsoever.
I use this code, so the wrap indicator is shown, and the indent works nice.
Code: Select all
ide=Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
If ide
SendMessage_(ide,#SCI_SETWRAPMODE,#True,0)
SendMessage_(ide,#SCI_SETWRAPSTARTINDENT,16,0) ; <-- indent amount
SendMessage_(ide,#SCI_SETWRAPVISUALFLAGS,#SC_WRAPVISUALFLAG_START,1)
EndIf
Posted: Thu Jan 03, 2008 5:16 pm
by DoubleDutch
Here is a new version, based upon the various suggestions and ideas:
Code: Select all
scintilla=Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
If scintilla
SendMessage_(scintilla,#SCI_SETWRAPVISUALFLAGS,#SC_WRAPVISUALFLAG_START,0)
SendMessage_(scintilla,#SCI_SETWRAPSTARTINDENT,16,0) ; <-- indent amount
SendMessage_(scintilla,#SCI_SETWHITESPACEFORE,#True,RGB($70,$50,$d0)) ; <- colour of marker
SendMessage_(scintilla,#SCI_SETWRAPMODE,1-SendMessage_(scintilla,#SCI_GETWRAPMODE,0,0),0)
EndIf
End
It looks like it's stable, and acts like an on/off switch. Install as a tool (it won't work otherwise), if you set it to run when source loaded then your default view should be wrapped source.
Many thanks to PB and MrMat.
WARNING: This is still an experimental editor hack, it may have unpredictable results (you may lose work) !!!
Posted: Thu Jan 03, 2008 5:24 pm
by Berikco
it's not a real line continuation character, where you can choose the position of a line break, but it helps me a lot

Posted: Thu Jan 03, 2008 5:30 pm
by DoubleDutch
imho the best option would be to have both methods available (they both have advantages).
I sometimes use a laptop with a touch pad, nothing is worse than a horizontal scroll bar on that laptop!

Vertical scrolls are easy because the laptops touchpad has a vscroll bar.
But for making code look a lot neater then a compiler based line continuation system would be better.
