Reformat whole source

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Reformat whole source

Post by blueznl »

Silly question, I know there's CTRL+I, but is there also a shortcut that will reformat the whole source at once?

Saves a bit of selecting, CTRL+I, etcetera.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Reformat whole source

Post by PB »

Ctrl+A followed by Ctrl+I ? :shock:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Reformat whole source

Post by Crusiatus Black »

PB wrote:Ctrl+A followed by Ctrl+I ? :shock:
ikr :shock:
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Reformat whole source

Post by blueznl »

Yeah, i know. But... that's multiple keystrokes, moves my cursor to a different line, and selects all. I often use reformat to keep track of my work (ie. I use CodeCaddy then hit Alt+r, and keep on working in the same area). By reformatting I can quickly spot if I missed a few EndIf's etcetera.

I know it's a matter of taste and workflow :-) I was just wondering if there was a single key without having to select anything.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Reformat whole source

Post by davido »

I, too, wouldn't mind a single key solution.

For now I use:

Hold control key and press: f2 a i
Release the control-key and press: f2

It is really very quick and I'm always less than half a screen away from where I was.
DE AA EB
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Reformat whole source

Post by IdeasVacuum »

It's a small limitation of the IDE really (as it is in many IDEs, including VS). I write my code using UltraEdit, formating on-the-fly with the wonderful column mode.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Reformat whole source

Post by blueznl »

davido wrote:I, too, wouldn't mind a single key solution.

For now I use:

Hold control key and press: f2 a i
Release the control-key and press: f2

It is really very quick and I'm always less than half a screen away from where I was.
That's close to what I want, now we only have to convince the developers to give us a one key reformat :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Reformat whole source

Post by davido »

Would it, perhaps, be possible to make a built-in tool to do that?

That is, unfortunately, way, way beyond my capability. :)
DE AA EB
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Reformat whole source

Post by Little John »

davido wrote:Would it, perhaps, be possible to make a built-in tool to do that?
A least on Windows, it's not hard to do so.

a) Get some good code for sending keystrokes:
I recommend the AutoWin library by ts-soft, with improvements by me. :-)

b) Write your own versatile generic Sendkeys program in 2 lines:

Code: Select all

XIncludeFile <Path> + "AutoWin_Include.pbi"
AW_SendKeys(ProgramParameter(0))
and compile it to an EXE file.

c) PB IDE > Tools > Configue tools > New:
Commandline:
<Path>\SendKeys.exe

Arguments:
"{CONTROLDOWN}{F2}ai{CONTROLUP}{DELAY 100}{F2}"

Name:
Reformat whole source

Event to trigger the tool:
Menu Or Shortcut


Note: Some delay before sending the second {F2} seems to be crucial. 100 ms is fine on my system, on other systems other values might be appropriate.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Reformat whole source

Post by davido »

Thank you, Little John. You make it look so simple! :wink:

I'll have a good look at that.
DE AA EB
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Reformat whole source

Post by PB »

> By reformatting I can quickly spot if I missed a few EndIf's etcetera.

If that's all you're worried about, then you do know the IDE has two
features to prevent that: matching keyword colors, and the line that
gets drawn between If/EndIf so you can see if any are mismatched.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Reformat whole source

Post by TI-994A »

Personally, I use AutoHotkey. It is configured via a simple text script and can automate single commands and even paragraphs. It's become an indispensable tool for me, automatically generating standard procedures, code blocks, and event loops at the press of a single key. For example, this entry in the script:

Code: Select all

F12::
Send {Raw} Enumeration
Send {Enter}
Send {Raw}   #MainWindow
Send {Enter}
Send {Raw} EndEnumeration
Send {Enter 2}
Send {Raw} wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
Send {Enter}
Send {Raw} OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "<Title>", wFlags)
Send {Enter 2}
Send {Raw} While WaitWindowEvent() ! #PB_Event_CloseWindow: CloseWindow: Wend
will generate this code block at a single touch of the F12 key:

Code: Select all

Enumeration
  #MainWindow
EndEnumeration

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "<Title>", wFlags)

While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow :Wend
Every keystroke counts. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Reformat whole source

Post by Little John »

Hi TI-994A,

I just thought that it might be more fun and more self-contained to compile a SendKeys program ourselves with PB. :-)

However, I agree that AutoHotkey is a great tool which can be used very effectively and flexible.
Post Reply