Page 1 of 1
lcb file snippet for the Atom editor
Posted: Thu Aug 27, 2015 8:06 am
by AndyP
I've created a snippet for the Atom editor to make creating .lcb files a little easier
In Atom
(you need to have Peters packages installed first)
Go File>Open Your Snippets
Add the following to the file
'.source.iRev, .source.lcb':
'lcbtemplate':
'prefix': 'lcbt'
'body': '-- declaring extension as widget, followed by identifier\n
widget community.livecode.username.identifier\n
use com.livecode.canvas\n
use com.livecode.widget\n
use com.livecode.engine\n
metadata title is "title"\n
metadata author is "author"\n
metadata version is "1.0.0"\n
end widget'
Then save the snippets file
Create a new .lcb file
This must be saved in order for Atom to be able to associate the .lcb file with Peters packages.
In the new .lcb file type
lcbt and hit enter or the tab key or pick it from the auto-complete options
You will now get this added to your .lcb file
-- declaring extension as widget, followed by identifier
widget community.livecode.username.identifier
use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
metadata title is "title"
metadata author is "author"
metadata version is "1.0.0"
end widget
Re: lcb file snippet for the Atom editor
Posted: Thu Aug 27, 2015 1:38 pm
by trevordevore
Thanks Andy!
Re: lcb file snippet for the Atom editor
Posted: Thu Aug 27, 2015 7:42 pm
by bn
Hi Andy,
thank you for your snippet. It saves a lot of repetetive typing.
Although I had trouble installing it by copying the snippet from the forum using Safari on a Mac I managed when I copied your snippet from the digest of the use-list from the email.
Atom was complaining about an unexpected end of line. Comparing both texts in BBEdit did not give me a clue as to why.
Anyways, thank you again.
Kind regards
Bernd
Re: lcb file snippet for the Atom editor
Posted: Thu Aug 27, 2015 11:44 pm
by bn
Hi Andy,
I like your idea so much that I added standard public handlers
Code: Select all
'.source.iRev, .source.lcb':
'lcbtemplate':
'prefix': 'lcbt'
'body': '-- declaring extension as widget, followed by identifier\n
widget community.livecode.username.identifier\n
use com.livecode.canvas\n
use com.livecode.widget\n
use com.livecode.engine\n
metadata title is "title"\n
metadata author is "author"\n
metadata version is "1.0.0"\n
\n
-- property yourProperty get mYourVariable set yourSetCommand
\n
\n
public handler OnLoad(in pProperties as Array)\n
-- your code here\n
put pProperties["myProperty"] into mMyVariable\n
end handler\n
\n
public handler OnSave(out rProperties as Array)\n
-- your code here\n
put the empty array into rProperties\n
put mMyVariable into rProperties["myProperty"]\n
return rProperties\n
end handler\n
\n
public handler OnCreate()\n
-- your code here\n
end handler\n
\n
public handler OnPaint()\n
-- your code here\n
end handler\n
\n
end widget'
Kind regards
Bernd
Re: lcb file snippet for the Atom editor
Posted: Sat Aug 29, 2015 5:52 pm
by AndyP
Hi Bernd,
Thanks, I'll be using this version from now.
As a side to this I'm playing with pushing and pulling text from the LC editor to Atom which sort of works

if this becomes stable I'll post a link to the scripts.
Re: lcb file snippet for the Atom editor
Posted: Sat Aug 29, 2015 6:22 pm
by Simon
Hi Bernd,
I'm getting that "unexpected newline" from your script now.
I thought it was this
Code: Select all
-- property yourProperty get mYourVariable set yourSetCommand
\n
but no luck.
Simon
Re: lcb file snippet for the Atom editor
Posted: Sat Aug 29, 2015 7:02 pm
by bn
Hi Simon,
here is the zipped snippets-file from Atom which on my Max is in an invisble folder right in
/users/theUser/.atom/snippets.cson
try to put it there.
This works for me if you open a new document and save it as xyz.lcb
then as AndyP explained type in the first line of the new document lcbt and then return or tab and it autofills with the snippet.
I have tried to find what is going on but have not succeeded, as stated above.
I hope the zipped file does the trick...
Kind regards
Re: lcb file snippet for the Atom editor
Posted: Sat Aug 29, 2015 7:19 pm
by Simon
Thanks Bernd,
That worked perfectly!
Simon
Re: lcb file snippet for the Atom editor
Posted: Mon Aug 31, 2015 7:10 pm
by peter-b
Hi Bernd,
Would you like to add these to my Atom package? I'm always keen to receive improvements!
Re: lcb file snippet for the Atom editor
Posted: Mon Aug 31, 2015 7:58 pm
by bn
Hi Peter,
peter-b wrote:Would you like to add these to my Atom package? I'm always keen to receive improvements!
I would love to give that AndyP (Andy Piddock) gets the credit for this very nice idea to make a snippet for the header of a LCB file. I just expanded his idea.
Where do you want me to put it?
Kind regards
Bernd
Re: lcb file snippet for the Atom editor
Posted: Mon Aug 31, 2015 8:58 pm
by peter-b
bn wrote:
I would love to give that AndyP (Andy Piddock) gets the credit for this very nice idea to make a snippet for the header of a LCB file. I just expanded his idea.
Where do you want me to put it?
Please send me a patch or submit a pull request to my GitHub repository (no CLA is needed, it's a community project

)
https://github.com/peter-b/atom-language-livecode
Thank you so much for contributing!
Re: lcb file snippet for the Atom editor
Posted: Thu Sep 03, 2015 12:59 am
by monte
Hi Folks
Nothing major to add but this version sorts out the indents and is a bit easier to edit:
EDIT
I had some more fun with this and this version will auto-select username first then you can tab to identifier, title etc.
I went looking for a way to define a variable somewhere central for author, username etc but it's not available yet. There appears to be some work going on for this but not yet complete:
https://github.com/atom/snippets/pull/83
Code: Select all
'.source.iRev, .source.lcb':
'lcbtemplate':
'prefix': 'lcbt'
'body': """
-- declaring extension as widget, followed by identifier
widget community.livecode.${1:username}.${2:identifier}
use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
metadata title is "${3:title}"
metadata author is "${4:author}"
metadata version is "${5:1.0.0}"
-- property yourProperty get mYourVariable set yourSetCommand
public handler OnLoad(in pProperties as Array)
-- your code here
put pProperties["myProperty"] into mMyVariable
end handler
public handler OnSave(out rProperties as Array)
-- your code here
put the empty array into rProperties
put mMyVariable into rProperties["myProperty"]
return rProperties
end handler
public handler OnCreate()
-- your code here
end handler
public handler OnPaint()
-- your code here
end handler
end widget
"""