It is currently Thu Jul 18, 2019 3:43 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Automatic splitting code across lines...
PostPosted: Thu Jan 03, 2008 12:13 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
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:
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:
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!!!

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Last edited by DoubleDutch on Thu Jan 03, 2008 5:17 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Automatic splitting code across lines...
PostPosted: Thu Jan 03, 2008 12:42 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
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.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 12:45 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
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.

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 12:51 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> 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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 12:54 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
I agree that would be the best solution.

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject: Re: Automatic splitting code across lines...
PostPosted: Thu Jan 03, 2008 2:06 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
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:
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 2:32 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
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.

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 2:48 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> 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:
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 2:55 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
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.

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 4:01 pm 
Offline
Enthusiast
Enthusiast

Joined: Sun Sep 05, 2004 6:27 am
Posts: 762
Location: England
It uses STYLE_DEFAULT. You can also override it with SCI_SETWHITESPACEFORE but i think that is for backwards compatibilty.

_________________
Mat


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 4:08 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
Thanks. :)

Looks like the message isn't depreciated so it should be ok to use.

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 4:13 pm 
Offline
Administrator
Administrator

Joined: Wed Apr 23, 2003 7:57 pm
Posts: 1321
Location: Belgium
Works fine here.
No problem whatsoever.
I use this code, so the wrap indicator is shown, and the indent works nice.

Code:
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

_________________
Berikco

http://www.vispluk.be


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 5:16 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
Here is a new version, based upon the various suggestions and ideas:

Code:
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) !!!

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Last edited by DoubleDutch on Thu Jan 03, 2008 5:39 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 5:24 pm 
Offline
Administrator
Administrator

Joined: Wed Apr 23, 2003 7:57 pm
Posts: 1321
Location: Belgium
it's not a real line continuation character, where you can choose the position of a line break, but it helps me a lot :)

_________________
Berikco

http://www.vispluk.be


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 03, 2008 5:30 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3106
Location: United Kingdom
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.

:)

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye