New feature - code snippets

William Lancee

Well-Known Member
Licensed User
Longtime User
I really like it. A super flexible macro renderer with facilitated insertions.
A very good way to use and share collections of useful theme related snippets.

Complex snippets are possible, but even simple snippets can make life easier.

B4X:
     'Loop.txt file in B4XLib: Code_Maps

'Iterates with respect to keys in a map.
For Each $varName$ As String In $mapName$.Keys

Next

   'Initialize.txt file in B4XLib: Code_Lists

'Declares and initializes an empty list.
Dim $listName$ As List
$listName$.Initialize

Bravo!
 

LucaMs

Expert
Licensed User
Longtime User
And, if so, how should/could I group them, for example by genre (graphics, strings, web, ...), to select one in the best, most direct way?
Well, like in this gif...

B4J_TgdenXgH64.gif


you don't necessarily have to start by writing "Code..."
so it will be sufficient to create your text files (the snippets) in such a way that you can filter them, if they are all part of a single library.
I mean, for example, my string snippets will probably have names like: str_RemoveSpaces and by just typing "str_" I can more easily select what I want to insert.

(I answered myself ?)
 

zed

Active Member
Licensed User
I think it's great.
No more searching for the code snippet.
Which is really annoying when you can't find it. Less time wasted
 

LucaMs

Expert
Licensed User
Longtime User
Well, like in this gif...

View attachment 146140

you don't necessarily have to start by writing "Code..."
so it will be sufficient to create your text files (the snippets) in such a way that you can filter them, if they are all part of a single library.
I mean, for example, my string snippets will probably have names like: str_RemoveSpaces and by just typing "str_" I can more easily select what I want to insert.

(I answered myself ?)


1.gif
 

AnandGupta

Expert
Licensed User
Longtime User
I still think, it is members hard work on snippets support third party application, that made Erel think about it in the ide itself.
Thanks to all members who made snippets copy easier for us by their contribution. ?
 

Magma

Expert
Licensed User
Longtime User

Daestrum

Expert
Licensed User
Longtime User
I like the idea of the snippets, but one text file per snippet, that's enough to stop me even trying it. (Sorry Erel)
 

LucaMs

Expert
Licensed User
Longtime User
I like the idea of the snippets, but one text file per snippet, that's enough to stop me even trying it. (Sorry Erel)
I understand your doubts but if you prepare a Snippets folder with the text files inside, keep it like this but compress it (7-zip or similar) in your own MySnippets.b4xlib (just change the extension) it is quite convenient.

And whoever is writing this to you is a member who would prefer to continue selling his tool (with source) ?

I too would prefer a snippets manager to be integrated into the IDE, like in MS Visual Studio, but Erel evidently has reasons not to do so.
 

aeric

Expert
Licensed User
Longtime User
[OK]...Now the bad news :rolleyes:... we must re-write all the threads with the snippets and change the "variables" with $variable$ !!!, and preferable at the first post attach a txt file snippet ! ?
So, my snippet looks like this:
B4X:
Private Sub Delete$Controller$ (id As Long)
    ' #Version = v2
    ' #Desc = Delete $Controller$ in MinimaList
    ' #Elements = [":id"]
    If id < 1 Then
        HRM.ResponseError = "Invalid id value"
        HRM.ResponseCode = 404
    Else
        Dim Index As Int = Main.$MinimaList$.IndexFromId(id)
        If Index < 0 Then
            HRM.ResponseError = "$Controller$ not found"
            HRM.ResponseCode = 404
        Else 
            Main.$MinimaList$.Remove(Index)
            HRM.ResponseCode = 200
        End If
    End If
    
    If Main.SimpleResponse Then
        WebApiUtils.ReturnSimpleHttpResponse(HRM, "List", Response)
    Else
        WebApiUtils.ReturnHttpResponse(HRM, Response)
    End If
    If Main.KVS_ENABLED Then Main.WriteKVS("$MinimaList$", Main.$MinimaList$)
End Sub

The IDE will highlight the variables. Once I replace the first variable, all other variables (with the same placeholder) will be replaced.

before:
1695372116021.png


after:
1695372225083.png
 
Last edited:

Magma

Expert
Licensed User
Longtime User

Daestrum

Expert
Licensed User
Longtime User
I know it comes down to personal choice. I was just saying my opinion. It's great that it has been added but personally I won't use it. (Same as I have never used the built in Debugger).
 
Top