New feature - code snippets

ilan

Expert
Licensed User
Longtime User
You can open the b4xlib archive with the 7-zip application.
Select the text file you want to edit and press Enter or F4.
Save the changes when asked.
View attachment 146382 View attachment 146383
Of course you have made a backup copy of the b4xlib file first...
And if you are using the b4xlib in a project you should refresh the list of the Library Manager.
i understand that this is possible but my point was that it would make more sense if there would be a code class where you can see all code and update when needed and not zip/unzip. anyway i think it is a very good idea. Great work Erel!
 

Peter Simpson

Expert
Licensed User
Longtime User
Creating a bank of code snippets is a matter of:
1. Putting all snippets (text files) in a folder named Snippets.
2. Zipping the folder and renaming it to CodeSnippets.b4xlib (or any other name).
I'm still trying to decide which I prefer to be honest.

I've basically transferred my code class over to separate snippet files (my code module has functions that I use a lot). I like the idea of the code snippets, I like it a lot and I totally agree with the concept.

I might give option 2 a go, zipping up the folder and seeing how that goes. Yes, with option 1 I have plenty of snippet files in the folder but that really doesn't bother me.

I'm looking at it like this. It's better to have the option there than not to have the option at all.

Thank you Erel, this feature will definitely come in really handy for me. I'm personally using it to quickly add functions to code like my number mapper and proper case to projects without having to add my entire code module that's full of extra functions that I use regularly.

I have a few ideas like your $map$ example that will definitely come in handy and save me development time in the future..

Thank you for this new code snippets feature, I will use it well ???
 

ilan

Expert
Licensed User
Longtime User
View attachment 146384

*** Another great and easy feature Erel can add... is having a small button "here" that will open the text file with notepad... that will boost code snippet editing !!!
i am not sure such thing is possible because you need to re-zip it again. maybe a IDE build-in text editor could do that and the zip process can be done in background after saving. but i really like the idea. Hard work for Erel easy work for us ?

btw. Erel any comments on this?:

1, will it fill now the suggestions dialog when start typing? What will happen if there would be 200 snippets? will it slow down the typing in the IDE because of the huge suggestion dialog?
 

Magma

Expert
Licensed User
Longtime User
i am not sure such thing is possible because you need to re-zip it again. maybe a IDE build-in text editor could do that and the zip process can be done in background after saving. but i really like the idea. Hard work for Erel easy work for us ?

btw. Erel any comments on this?:
I was talking for snippets folder :) - not for b4xlib...
 

Daestrum

Expert
Licensed User
Longtime User
Apologies Erel for my comment, it was never meant to be so abrupt, and I definately never meant to offend.

Please accept my sincerest apology.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
i am not sure such thing is possible because you need to re-zip it again. maybe a IDE build-in text editor could do that and the zip process can be done in background after saving. but i really like the idea. Hard work for Erel easy work for us
You currently have two options to manage and distribute snippets:
1. Simply put the text files inside the snippets folder. This is a folder that you create inside the additional libraries folder. It must be named Snippets. Starting from beta #2 you can create subfolders inside the snippets folder for better organization. Note that you need to click on Libraries - Refresh to reload a file.
2. Create a b4xlib (=zip file) with Snippets folder. This is more suitable for distribution as part (or not) of a library.

, will it fill now the suggestions dialog when start typing? What will happen if there would be 200 snippets? will it slow down the typing in the IDE because of the huge suggestion dialog?
I've just tested it with 400 snippets and didn't see any regression.
The snippets are only included on the autocomplete of the first word in line and even on that word it works fast.
It does make sense if you have hundreds of snippets to put them in b4xlibs and only reference the relevant collections.
 

Magma

Expert
Licensed User
Longtime User
B4X:
#include file="\with\full\path\xxxxx"   'also show an icon for notepad editing... beside it

I don't remember in what language was... pascal... not remember...

may be Another wish... that has a relationship with all these (not only for snippets) but general adding more code and have better structure...

have a command like include that will "merge" code from other file (text based)... i think will be also helpful
 

mangojack

Expert
Licensed User
Longtime User
I haven't tried it and therefore I don't know if the .txt extension is mandatory for the IDE to recognize the file

I did try a file with .mp4 extension .. but the IDE just displayed Code_ of Silence (1984) ... Don't you just love Chuck though :oops:
 

stevel05

Expert
Licensed User
Longtime User
1. Simply put the text files inside the snippets folder.
Can I just clarify this point. Do you mean:

1695730608011.png

Like this?

As it doesn't appear to work unless I move the Snippets folder into the B4j folder (in my case).
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
Can I just clarify this point. Do you mean:

View attachment 146389
Like this?

As it doesn't appear to work unless I move the Snippets folder into the B4j folder (in my case).
Yes or place it in B4X folder so as to support B4A, and B4i When they also receive the update
 

LucaMs

Expert
Licensed User
Longtime User
No.
Cross platform snippets should go into B4X\Snippets
Non-cross platform should go into B4J\Snippets
It seems so simple to me! Create a b4xlib for each language: B4A, B4J, B4i and B4X for snippets that work with each language.

I also noticed that compared to Visual Studio snippets, these are much more convenient to use!
 

Cableguy

Expert
Licensed User
Longtime User
I was wondering...
Why the choice of "code" and not the more obvious "snippet"?
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Well, it is real code and "snippet" takes up more room.
I'm old school and I am more familiar with "macro" then with "snippet", but '"code" works for me.

And..
A "code snippet" is a reusable block of code. "code" is just shorthand for "code snippet".

And...
This is when every one's eyes glaze over!
 
Last edited:
Top