[Tip] Procedure "index" at the top of your source

Share your advanced PureBasic knowledge/code with the community.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

[Tip] Procedure "index" at the top of your source

Post by Dude »

I hate pressing F2 to jump to bookmarked procedures of my sources. It's okay, but I'm often hitting F2 repeatedly until I get to the procedure that I want. Not fun.

Since I knew we can hold down Ctrl and DoubleClick a procedure name to immediately jump to it, it suddenly hit me today that why not make an "index" of procedure names at the top of my source so that I can Ctrl+DoubleClick to them quickly? I tried this with comments at first, but comments can't be clicked that way, so I did it with a section of code that isn't compiled into your exe when built. It's as simple as this:

Code: Select all

CompilerIf 0 ; This block not compiled into the exe. :)
  GlobalVars() : MainLoop() : Tweaks() : QuitApp()
  LoadSettings() : SaveSettings() : Screenshot()
CompilerEndIf
Now when my source loads, I can immediately Ctrl+DoubleClick any procedure to jump right to it. 8) Same if I'm elsewhere in the middle of my source: I just press Ctrl+Home to go to the top of my source, and Ctrl+DoubleClick a procedure name again. This has made my source navigation to my procedures so much more convenient than hitting F2 to find them.

You can even "bookmark" non-procedure parts of your source with procedure names that never get compiled:

Code: Select all

CompilerIf 0
  Procedure GlobalVars() ; Fake procedure to jump to global vars quickly. ;)
  EndProcedure
CompilerEndIf
Global who,why,what,when,where,etc...
Hope this tip helps someone else. :)
Last edited by Dude on Sat Dec 29, 2018 12:33 pm, edited 3 times in total.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Marc56us »

Personally I use the "Procedure Browser" panel and I tell him to also put the "Issues" (ie: Todo, bugfix etc.).
A simple click on right panel automatically takes me to all the procedures and things "to do", "to fix".

IDE configuration to do this:

:arrow: Preference > ToolsPanel > add Procedure Browser

And to see in this panel "Todo, Bug, Info etc"
:arrow: Preference > Issues > ... (keyword) [X] Show in procedure browser

+ When running in project mode, all procedures and issues of the project are listed in the same panel.

:wink:
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: [Tip] Procedure "index" at the top of your source

Post by TI-994A »

Dude wrote:...we can hold down Ctrl and DoubleClick a procedure name to immediately jump to it, it suddenly hit me today that why not make an "index" of procedure names at the top of my source so that I can Ctrl+DoubleClick to them quickly?
Thanks for the tip; very resourceful.

Just curious though; why not just use the IDE's built-in Procedure Browser?
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
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Dude »

Marc56us wrote:Personally I use the "Procedure Browser" panel
The "Procedure Browser" panel is good for short sources, but my source has over 200 procedures and so my panel is very, very long... way too long to bother scrolling through to find a single procedure name in the middle of that large haystack.

And as I pointed out, it's also good for instantly jumping to non-procedure code too, like a global var block (which wouldn't appear in the "Procedure Browser").

That's why my tip came about. ;)
Last edited by Dude on Sat Dec 29, 2018 11:39 am, edited 2 times in total.
Everything
Enthusiast
Enthusiast
Posts: 224
Joined: Sat Jul 07, 2018 6:50 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Everything »

Declare will do the same thing as your snippet, but still nice trick, thx!
Last edited by Everything on Sat Dec 29, 2018 11:37 am, edited 1 time in total.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Dude »

Everything wrote:Declare will do the same thing as your snippet.
Nope, because then you need to declare all the procedure parameters as well, instead of just the name. ;)

And you can't use Declare for the second purpose of my tip, which is to instantly jump to non-procedure sections of code.
Everything
Enthusiast
Enthusiast
Posts: 224
Joined: Sat Jul 07, 2018 6:50 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Everything »

Dude wrote:you need to declare all the procedure parameters as well
That's true, however if you declare procedures anyway (if you do) than you can use declare block fore same purposes.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Dude »

Declare is ugly:

Code: Select all

Declare ResetSettings(file$,forfiles=1,forkeys=0,forimages=0) : Declare LoadSettings(file$) : Declare SaveSettings(file$)

Procedure ResetSettings(file$,forfiles=1,forkeys=0,forimages=0)
EndProcedure

Procedure LoadSettings(file$)
EndProcedure

Procedure SaveSettings(file$)
EndProcedure
Compare the above to my tip:

Code: Select all

CompilerIf 0
  ResetSettings() : LoadSettings() : SaveSettings()
CompilerEndIf

Procedure ResetSettings(file$,forfiles=1,forkeys=0,forimages=0)
EndProcedure

Procedure LoadSettings(file$)
EndProcedure

Procedure SaveSettings(file$)
EndProcedure
And trying to make it "neater" with one Declare per line means you run into the same problem as the "Procedure Browser": scrolling in your Declare block to find the procedure name. With over 200 procedures, this is no better than just using the browser.

With my tip, no scrolling is needed, and you can also instantly jump to non-procedure sections of code. ;)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [Tip] Procedure "index" at the top of your source

Post by davido »

@Dude,
Took me a while to see the merit in your idea. :oops:

I always have my Declares at the top of the code and add to them as Procedures are added.
So I did not think much of the idea - until I tried it out.

So far I have tried:
1. Grouping Procedures
2. Shortening names
3. Using comments to make sense of the shortened names.

I think it can only get better as I use it.

Great Idea, in my humble opinion. :D
Last edited by davido on Sat Dec 29, 2018 4:52 pm, edited 1 time in total.
DE AA EB
HanPBF
Enthusiast
Enthusiast
Posts: 563
Joined: Fri Feb 19, 2010 3:42 am

Re: [Tip] Procedure "index" at the top of your source

Post by HanPBF »

viewtopic.php?f=18&t=65794

Did not read the details (of both threads :?).

It's all about organizing source code and lacking features in an editor.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Marc56us »

If you do not want Procedures Browser, uses issues (notes) as markers then show issue browser as floatting window or in panel.
Double-click go to line immediatly

PB help
Image

Personally I put markers on the important sections (Enumeration, Initialization, Main loop, Include and of course Todo and Bug to fix)

The other interest is that the markers of all open files or projects are visible in the same window

PB IDE is simple but does everything.

:wink:
Last edited by Marc56us on Sat Dec 29, 2018 2:48 pm, edited 3 times in total.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Dude »

I never saw that post before (2.5 years ago). Same concept, different layout. But yes, HanPBF did it first. :)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Tip] Procedure "index" at the top of your source

Post by Dude »

Marc56us, you're missing the point. Issues doesn't do what this tip does at all because the tip is to not have to scroll through a very long list to find what you want, and neither is the tip to mark anything like you do with the Issues tool (otherwise I'd just use F2 again to set bookmarks).

And like I said, it's quicker to just press Ctrl+Home to go to the top of my source and Ctrl+DoubleClick a procedure name, than to click the Tools menu, select "Issues Browser", then scroll through 200+ procedure "issues" to find the one you want. ;)
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: [Tip] Procedure "index" at the top of your source

Post by Bisonte »

Dude wrote:And as I pointed out, it's also good for instantly jumping to non-procedure code too, like a global var block (which wouldn't appear in the "Procedure Browser").

That's why my tip came about. ;)
Not really true.

Code: Select all

Procedure Foo()
EndProcedure

;- Var Block
Will show in the procedure browser

Code: Select all

Foo()
> Var Block
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [Tip] Procedure "index" at the top of your source

Post by skywalk »

Nice trick, but still a lot of dead typing.
Using the Procedure Browser is limited, but better than nothing.
Naming conventions help and I add a ";-!" suffix to important areas of code.
These appear at the top of the Procedure Browser and in alphabetic order if selected in preferences.

How do you get the Issue Browser as a floating window? :shock:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply