lcb file snippet for the Atom editor

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
AndyP
Posts: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

lcb file snippet for the Atom editor

Post by AndyP » Thu Aug 27, 2015 8:06 am

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
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: lcb file snippet for the Atom editor

Post by trevordevore » Thu Aug 27, 2015 1:38 pm

Thanks Andy!
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: lcb file snippet for the Atom editor

Post by bn » Thu Aug 27, 2015 7:42 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: lcb file snippet for the Atom editor

Post by bn » Thu Aug 27, 2015 11:44 pm

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

AndyP
Posts: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: lcb file snippet for the Atom editor

Post by AndyP » Sat Aug 29, 2015 5:52 pm

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.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: lcb file snippet for the Atom editor

Post by Simon » Sat Aug 29, 2015 6:22 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: lcb file snippet for the Atom editor

Post by bn » Sat Aug 29, 2015 7:02 pm

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
Attachments
snippets.cson.zip
(542 Bytes) Downloaded 257 times

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: lcb file snippet for the Atom editor

Post by Simon » Sat Aug 29, 2015 7:19 pm

Thanks Bernd,
That worked perfectly!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

peter-b
Posts: 182
Joined: Thu Nov 20, 2014 2:14 pm
Location: LiveCode Ltd.

Re: lcb file snippet for the Atom editor

Post by peter-b » Mon Aug 31, 2015 7:10 pm

Hi Bernd,

Would you like to add these to my Atom package? I'm always keen to receive improvements!
LiveCode Open Source Team — @PeterTBBrett — peter.brett@livecode.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: lcb file snippet for the Atom editor

Post by bn » Mon Aug 31, 2015 7:58 pm

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

peter-b
Posts: 182
Joined: Thu Nov 20, 2014 2:14 pm
Location: LiveCode Ltd.

Re: lcb file snippet for the Atom editor

Post by peter-b » Mon Aug 31, 2015 8:58 pm

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 8) )

https://github.com/peter-b/atom-language-livecode

Thank you so much for contributing!
LiveCode Open Source Team — @PeterTBBrett — peter.brett@livecode.com

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: lcb file snippet for the Atom editor

Post by monte » Thu Sep 03, 2015 12:59 am

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
   """
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “LiveCode Builder”