Jump to content




CC Syntax Highlighting/Code Completions v1.2 - Sublime Text 2

utility lua

  • You cannot reply to this topic
133 replies to this topic

#1 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 20 February 2013 - 01:59 AM

Hey all,

I wrote a new ComputerCraft package for the text editor Sublime Text 2, which builds upon the current Lua one and includes colouring and code completions for all of the CC APIs. It also fixes the issue where the re-indent feature wouldn't work (it wouldn't code-fold at elseifs, or at functions defined in the way shown below), so you are able to use re-indent on screwed up code! :D It also adds support for declaring functions like this:
func = function(arg1, arg2, ...)
  print(tostring(arg1) .. "  " .. tostring(arg2) .. " " .. table.concat({...}, " "))
end

These functions will now be syntax-highlighted properly, and appear in the functions list when Go To Symbol (command/control+R) is selected :D

Features
- Syntax highlighting for every CC API function
- Syntax highlighting for every CC constant (keys.* and colours.*)
- Code completion for all main CC functions
- New default snippets relating to CC (clear screen, center print, BSoD template, proper checking if the computer is an advanced computer)
- Support for declaring functions 2 different ways (described above)
- Fixed the re-indent feature (Edit -> Line -> Reindent)
- Opening .lua files defaults to this syntax
- Multiline commenting using block comments (--[[ and ]]--)
- Fixed functions declared in the way shown above not re-indenting

Download
GitHub Repository: https://github.com/G...erCraft-Package

Installation
1. Download and install Sublime Text 2's Package Control Plugin
2. Open the command palette (Tools -> Command Palette, or Control+Shift+P / Command+Shift+P)
3. Search for Package Control: Install Packages
4. Search for ComputerCraft Package in the listings
5. Hit enter
6. Restart Sublime Text!

Installation for Linux in Sublime Text 3
  • Open Sublime
  • Click Preferences > Browse packages
  • Copy path to this dir
  • Open Terminal
  • CD into that dir
  • run git clone https://github.com/w...age_control.git "Package Control"
  • CD into Package\ Control
  • run git checkout python3
  • Restart ST3
  • Click Preferences > Package Control > Package Control: Install Package
  • Choose ComputerCraft Package
  • Wait fot it to download and install
  • Done!

Credits
- NeverCast for the idea in his Sublime 2 Plugin for Auto-Lua Syntax (another very useful ST2 plugin)
- ChrisJay for the list of all CC functions used in the code completion :D
- TheOriginalBIT for tonnes of suggestions

Usage
To use it after you've installed it, just set the syntax to ComputerCraft (it should appear as an option once you've installed it). You can access the set syntax feature from the command palette (Tools -> Command Palette, or Shift+Control+P), and just look for Set Syntax: ComputerCraft. The syntax is also set as the default syntax for opening Lua files (.lua) when you install it.

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 20 February 2013 - 02:24 AM

This is awesome, thanks!

Also, path for windows is %APPDATA%/Sublime Text 2/Packages, and for linux, it's ~/.config/sublime-text-2/Packages.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 02:27 AM

You broke auto commenting.

#4 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 20 February 2013 - 02:35 AM

View PostTheOriginalBIT, on 20 February 2013 - 02:27 AM, said:

You broke auto commenting.

I'm no where near familiar with all of Sublime Text's features. Auto commenting? :P

I think I may know how to fix it. Plus, completions for all of the functions coming soon, as soon as I can work out how :P

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 02:37 AM

View PostGravityScore, on 20 February 2013 - 02:35 AM, said:

I'm no where near familiar with all of Sublime Text's features. Auto commenting? :P
I think I may know how to fix it. Plus, completions for all of the functions coming soon, as soon as I can work out how :P
Yeh, press ⌘ + / and it turns all the selected lines into comments

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 02:51 AM

Second Report. I iterated through _G printing out all the functions and variables. There are a few you missed, take a look at the output in Sublime too see what. :)

EDIT: Oh there is a bug in the iteration, the native. functions are obviously term.native ... but I assume you would know that :)

I also suggest that variables and functions should also highlight when _G. is at the front though, its still a valid function call/variable

The Output


The Code I Used To Do This (In case you're interested)
Spoiler

Edited by TheOriginalBIT, 20 February 2013 - 02:54 AM.


#7 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 20 February 2013 - 02:55 AM

Fixed it (the commenting)! Easy fix, just new installation method needed. I also re-added everything from the Lua code completions (for loops, functions, and a new clear terminal one). I'll release it in a sec, just finishing up something else.

EDIT: fixed the ones I missed.

#8 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 20 February 2013 - 03:26 AM

Updated OP with changes.

- Fixed all the Lua code snippets, and added a few more (clear screen and is advanced computer).
- Added in code completion for the more commonly typed CC API functions (term commands, io, fs, and a few os).
- Fixed auto commenting.
- Added in the colouring for the functions I missed

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 03:35 AM

View PostGravityScore, on 20 February 2013 - 03:26 AM, said:

and added a few more (clear screen and is advanced computer).

View PostGravityScore, on 20 February 2013 - 03:26 AM, said:

- Added in the colouring for the functions I missed (they must not be on the wiki :P).
I can tell you that "redstone.getInput()" is :P so is "fs.getFreeSpace()" and "read()" is really common............. but I'll stop there ;) :P

Still missed term.native too ;)

#10 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 20 February 2013 - 03:42 AM

View PostTheOriginalBIT, on 20 February 2013 - 03:35 AM, said:

View PostGravityScore, on 20 February 2013 - 03:26 AM, said:

and added a few more (clear screen and is advanced computer).

View PostGravityScore, on 20 February 2013 - 03:26 AM, said:

- Added in the colouring for the functions I missed (they must not be on the wiki :P).
I can tell you that "redstone.getInput()" is :P so is "fs.getFreeSpace()" and "read()" is really common............. but I'll stop there ;) :P

Still missed term.native too ;)

Arggggshsspppspweofijwoeifj034g9w8hgojiwoifjiodklscm...
I missed them then :P

- term.native.* is fixed

#11 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 20 February 2013 - 03:43 AM

I am getting a file no found on Jumpshare. Some of Jumpshare's other pages seem to be down as well. I suggest re-uploading to another service such as MEGA or Mediafire.

#12 tesla1889

  • Members
  • 351 posts
  • LocationSt. Petersburg

Posted 20 February 2013 - 03:44 AM

reminds me of something ive been putting off lol

same thing, but for gedit

#13 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 20 February 2013 - 03:45 AM

View PostSammich Lord, on 20 February 2013 - 03:43 AM, said:

I am getting a file no found on Jumpshare. Some of Jumpshare's other pages seem to be down as well. I suggest re-uploading to another service such as MEGA or Mediafire.

Huh. Works for me. I'll re-upload to Mega anyway, I like it more :P

#14 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 03:50 AM

View PostGravityScore, on 20 February 2013 - 03:42 AM, said:

Arggggshsspppspweofijwoeifj034g9w8hgojiwoifjiodklscm...
I missed them then :P

- term.native.* is fixed
Find keys variables fixed, and a few minor functions you missed. :)
http://pastebin.com/YHu5HuYV

#15 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 20 February 2013 - 03:52 AM

I used this for 5 minutes and I love it. I was switching to Sublime for all my website development and I was going to do the same and now since I have the syntax highlighting for CC I can do stuffz 10 times easier. :D Thanks Grav.

#16 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 03:53 AM

View PostSammich Lord, on 20 February 2013 - 03:52 AM, said:

I used this for 5 minutes and I love it. I was switching to Sublime for all my website development and I was going to do the same and now since I have the syntax highlighting for CC I can do stuffz 10 times easier. :D Thanks Grav.
Combine it with this slightly modified and its truly awesome! http://www.computerc...uto-lua-syntax/

#17 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 20 February 2013 - 03:55 AM

View PostTheOriginalBIT, on 20 February 2013 - 03:53 AM, said:

View PostSammich Lord, on 20 February 2013 - 03:52 AM, said:

I used this for 5 minutes and I love it. I was switching to Sublime for all my website development and I was going to do the same and now since I have the syntax highlighting for CC I can do stuffz 10 times easier. :D Thanks Grav.
Combine it with this slightly modified and its truly awesome! http://www.computerc...uto-lua-syntax/
Already downloaded this :P

#18 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 20 February 2013 - 03:55 AM

Now make it for notead++

#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 February 2013 - 03:56 AM

View PostSammich Lord, on 20 February 2013 - 03:55 AM, said:

Already downloaded this :P
Haha nice ;) change it to ComputerCraft instead of Lua then :)

View Posturielsalis, on 20 February 2013 - 03:55 AM, said:

Now make it for notead++
Sublime Text 2 is multi-os... so this is the better one to make it for :P

#20 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 20 February 2013 - 03:58 AM

View Posturielsalis, on 20 February 2013 - 03:55 AM, said:

Now make it for notead++
IMHO, Sublime Text 2 is far better than Notepad++ for a few reasons.

-Nicer themes(Gotta love the colors) :P
-Cross-Platform(Linux, Mac and Windows)
-Auto-Complete(Gotta love it)
-Automatically add functions to auto-complete after defining them
-More languages built in(Shit ton of languages already installed)
-You can use a un-timed trial of it or but the whole thing for $70

I think I made a pretty good case.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users