Difference between revisions of "Sublime Text"

m (more useful introduction)
(reworked titles, made compact and easier to follow, I hope)
Line 1: Line 1:
The following instructions work both in [http://sublimetext.com/ Sublime Text] 2 and 3
+
The following instructions work both in [http://sublimetext.com/ Sublime Text] 2 and 3 unless mentioned otherwise.
  
== Autocompletition & Building with the LuaLove Package ==
+
== Lua Love ==
  
Install the [https://sublime.wbond.net/packages/Lua%20Love LuaLove Package] via [https://sublime.wbond.net/installation#st2 Package Control] and modify the build system (slightly) to make running in love the default:
+
The [https://sublime.wbond.net/packages/Lua%20Love Lua Love Package] provides syntax highlighting, snippets, autocompletion and build rules.
''C:\Users\....\AppData\Roaming\Sublime Text 2\Packages\Lua Love\LuaLove.sublime-build'':
+
 
 +
# Install [https://packagecontrol.io/installation Package Control], restart Sublime.
 +
# Press Ctrl+Shift+P to open the '''command palette''' and use the '''Package Control: Install Package''' command.
 +
# Wait until another input field appears and install the '''Lua Love''' package.
 +
# In the '''command palette''' enable syntax highlighting with '''Set Syntax: Lua (Love)'''.
 +
# In Sublime 3, you can use Ctrl+Shift+B to select the build system '''LuaLove - Love2D''' which from then on you can start using Ctrl+B.
 +
# In Sublime 2, you have to manually edit the build script (<code>C:\Users\....\AppData\Roaming\Sublime Text 2\Packages\Lua Love\LuaLove.sublime-build</code> in Windows):
  
 
<source lang="ini">{
 
<source lang="ini">{
Line 34: Line 40:
 
</source>
 
</source>
  
== Without Packages  ==
+
Both Sublime 2 and 3 require the directory of your LÖVE binary to be part of your [[PATH]] variable. You can avoid this by changing the <code>"love"</code> path in the build script. This is [http://stackoverflow.com/questions/21190392/how-to-change-default-code-snippets-in-sublime-text-3 more complicated in Sublime 3].
  
=== On Windows ===
+
== Simple Build System  ==
Create a new Build System first: Tools -> Build System -> New Build System
+
  
Then paste the following code:
+
Create a new Build System: <code>Tools -> Build System -> New Build System</code> and use the following code.
 +
 
 +
'''Windows:'''
 
<source lang="ini">
 
<source lang="ini">
 
{
 
{
Line 48: Line 55:
 
}
 
}
 
</source>
 
</source>
 
+
'''Mac OS X:'''
Save it in the suggested location as <code>love-run.sublime-build</code>.
+
 
+
Now you can use CTRL + B to run your love project. Note that this code doesn't seem to work if you have spaces in your $file_path.
+
 
+
=== On Mac OS X ===
+
 
+
Create a new Build System first: Tools -> Build System -> New Build System
+
 
+
Then paste in the following code:
+
 
<source lang="ini">
 
<source lang="ini">
 
{
 
{
Line 65: Line 63:
 
}
 
}
 
</source>
 
</source>
(This is assuming that your love.app is in the Applications folder)
+
'''Linux:'''
 
+
Save it in the suggested location as <code>love-run.sublime-build</code>.
+
 
+
Now you can use CMD + B to run your love project.
+
 
+
=== On Linux ===
+
 
+
Create a new Build System first: Tools -> Build System -> New Build System
+
 
+
Then paste in the following code:
+
 
<source lang="ini">
 
<source lang="ini">
 
{
 
{
Line 86: Line 74:
 
Save it in the suggested location as <code>love-run.sublime-build</code>.
 
Save it in the suggested location as <code>love-run.sublime-build</code>.
  
Now you can use CTRL + B to run your love project.
+
Now you can use Ctrl+B or Cmd+B to run your love project.
 +
 
 +
=== Issues ===
 +
 
 +
* This build system depends on the location of your LÖVE binary. Check the path in the <code>"cmd":</code> line.
 +
* This code doesn't seem to work if you have spaces in your <code>$file_path</code>.
 +
* This code only seems to work when working with files in the same folder as <code>main.lua</code>.
  
== Displaying live console output in Sublime Text 2 ==
+
== Console output ==
  
 
By default the console in Sublime Text will not display any output, such as print() calls, until the LOVE application has been closed.
 
By default the console in Sublime Text will not display any output, such as print() calls, until the LOVE application has been closed.
  
To make the console output display live add the following code to the top of your main.lua file, or inside [[conf.lua]]:
+
To make the console output display live add the following code to the top of your <code>main.lua</code> file, or inside <code>[[conf.lua]]</code>:
 
<source lang="lua">
 
<source lang="lua">
 
io.stdout:setvbuf("no")
 
io.stdout:setvbuf("no")

Revision as of 05:33, 8 May 2016

The following instructions work both in Sublime Text 2 and 3 unless mentioned otherwise.

Lua Love

The Lua Love Package provides syntax highlighting, snippets, autocompletion and build rules.

  1. Install Package Control, restart Sublime.
  2. Press Ctrl+Shift+P to open the command palette and use the Package Control: Install Package command.
  3. Wait until another input field appears and install the Lua Love package.
  4. In the command palette enable syntax highlighting with Set Syntax: Lua (Love).
  5. In Sublime 3, you can use Ctrl+Shift+B to select the build system LuaLove - Love2D which from then on you can start using Ctrl+B.
  6. In Sublime 2, you have to manually edit the build script (C:\Users\....\AppData\Roaming\Sublime Text 2\Packages\Lua Love\LuaLove.sublime-build in Windows):
{
	"file_regex": "^(?:(?:\t)|(?:.+: ))(.+):([0-9]+): (.*)$",
	"selector": "source.lua",
	"shell": true,
	"cmd": ["love", "${project_path:${file_path:.}}"],
 
	"variants": [
		{
			"name": "Love2D",
			"shell": true,
			"cmd": ["love", "${project_path:.}"],
			"osx":
			{
				"cmd": ["love $project_path"]
			}
		},
		{   "name": "ldoc: File",
			"shell": true,
			"cmd": ["ldoc -d $project_path/doc/$file_base_name -f markdown -t $file_base_name $file"]
		},
		{   "name": "ldoc: Project",
			"shell": true,
			"cmd": ["ldoc -d $project_path/doc -f markdown -t $project_base_name $project_path/src/"]
		}
	]
}

Both Sublime 2 and 3 require the directory of your LÖVE binary to be part of your PATH variable. You can avoid this by changing the "love" path in the build script. This is more complicated in Sublime 3.

Simple Build System

Create a new Build System: Tools -> Build System -> New Build System and use the following code.

Windows:

{
    "selector": "source.lua",
    "cmd": ["C:/Program Files/LOVE/love.exe", "${project_path:${file_path}}"],
    "shell": true,
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$"
}

Mac OS X:

{
    "selector": "source.lua",
    "cmd": ["/Applications/love.app/Contents/MacOS/love", "${project_path:${file_path}}"],
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$"
}

Linux:

{
    "selector": "source.lua",
    "cmd": ["love", "${project_path:${file_path}}"],
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$"
}

Save it in the suggested location as love-run.sublime-build.

Now you can use Ctrl+B or Cmd+B to run your love project.

Issues

  • This build system depends on the location of your LÖVE binary. Check the path in the "cmd": line.
  • This code doesn't seem to work if you have spaces in your $file_path.
  • This code only seems to work when working with files in the same folder as main.lua.

Console output

By default the console in Sublime Text will not display any output, such as print() calls, until the LOVE application has been closed.

To make the console output display live add the following code to the top of your main.lua file, or inside conf.lua:

io.stdout:setvbuf("no")

Jumping to errors

If there was an error during execution, you can use the F4 (next error) and SHIFT-F4 (previous error) to go through the errors that lua encountered.

See also