Automatic splitting code across lines...

Working on new editor enhancements?
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Automatic splitting code across lines...

Post 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!!!
Last edited by DoubleDutch on Thu Jan 03, 2008 5:17 pm, edited 1 time in total.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Automatic splitting code across lines...

Post by PB »

Good one! :D 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. :)
Last edited by PB on Thu Jan 03, 2008 2:23 pm, edited 1 time in total.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I agree that would be the best solution.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Automatic splitting code across lines...

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :(

Image

> 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

It uses STYLE_DEFAULT. You can also override it with SCI_SETWHITESPACEFORE but i think that is for backwards compatibilty.
Mat
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Thanks. :)

Looks like the message isn't depreciated so it should be ok to use.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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 
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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. :)

Image

WARNING: This is still an experimental editor hack, it may have unpredictable results (you may lose work) !!!
Last edited by DoubleDutch on Thu Jan 03, 2008 5:39 pm, edited 2 times in total.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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 :)
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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! :evil: 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.

:)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply