Difference between revisions of "Sublime Text"

m (more useful introduction)
m (Instalation: misspelling)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The following instructions work both in [http://sublimetext.com/ Sublime Text] 2 and 3
+
Fast and customizable cross-platform code editor.
  
== Autocompletition & Building with the LuaLove Package ==
+
[[File:lualove.png|right|thumb|Sublime Text with [https://packagecontrol.io/packages/Lua%20Love Lua Love package] on Linux]]
  
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:
+
== Lua Love package ==
''C:\Users\....\AppData\Roaming\Sublime Text 2\Packages\Lua Love\LuaLove.sublime-build'':
 
  
<source lang="ini">{
+
The [https://packagecontrol.io/packages/Lua%20Love Lua Love Package] provides syntax highlighting, snippets, autocompletion and build systems.
"file_regex": "^(?:(?:\t)|(?:.+: ))(.+):([0-9]+): (.*)$",
 
"selector": "source.lua",
 
"shell": true,
 
"cmd": ["love", "${project_path:${file_path:.}}"],
 
  
"variants": [
+
=== Installation ===
{
+
# Install [https://packagecontrol.io/installation Package Control] and restart Sublime Text
"name": "Love2D",
+
# Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> to open the '''Command palette''' and enter '''Package Control: Install Package'''
"shell": true,
+
# Wait until another input field appears and install the '''Lua Love''' package
"cmd": ["love", "${project_path:.}"],
+
# In the '''Command palette''' enable syntax highlighting with '''Set Syntax: LOVE'''
"osx":
+
# Now select build system with <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to '''LuaLove''' and then you can use <kbd>Ctrl</kbd>+<kbd>B</kbd> to start LOVE.
{
+
# '''Optional''': Set LOVE syntax as default for all .lua files - <code>View</code>→<code>Syntax</code>→<code>Open all with current extension as...</code>→<code>LOVE</code>
"cmd": ["love $project_path"]
+
# '''Optional''': If LOVE is not in your [[PATH]] variable, go to <code>Preferences</code>→<code>Package Settings</code>→<code>Lua Love</code> and add:
}
+
<source lang="json">
},
 
{  "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/"]
 
}
 
]
 
}
 
</source>
 
 
 
== Without Packages  ==
 
 
 
=== On Windows ===
 
Create a new Build System first: Tools -> Build System -> New Build System
 
 
 
Then paste the following code:
 
<source lang="ini">
 
 
{
 
{
     "selector": "source.lua",
+
     "build_system.love.cmd": ["absolute/path/to/love/executable", "${project_path:${folder:${file_path}}}"]
    "cmd": ["C:/Program Files/LOVE/love.exe", "${project_path:${file_path}}"],
 
    "shell": true,
 
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$"
 
 
}
 
}
 
</source>
 
</source>
  
Save it in the suggested location as <code>love-run.sublime-build</code>.
+
=== Console output ===
  
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.
+
By default the console in Sublime Text will not display any output, such as <code>print()</code> calls, until the LOVE application has been closed.
  
=== On Mac OS X ===
+
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>:
 
 
Create a new Build System first: Tools -> Build System -> New Build System
 
 
 
Then paste in the following code:
 
<source lang="ini">
 
{
 
    "selector": "source.lua",
 
    "cmd": ["/Applications/love.app/Contents/MacOS/love", "${project_path:${file_path}}"],
 
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$"
 
}
 
</source>
 
(This is assuming that your love.app is in the Applications folder)
 
 
 
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">
 
{
 
    "selector": "source.lua",
 
    "cmd": ["love", "${project_path:${file_path}}"],
 
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$"
 
}
 
</source>
 
 
 
Save it in the suggested location as <code>love-run.sublime-build</code>.
 
 
 
Now you can use CTRL + B to run your love project.
 
 
 
== Displaying live console output in Sublime Text 2 ==
 
 
 
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]]:
 
 
<source lang="lua">
 
<source lang="lua">
io.stdout:setvbuf("no")
+
io.stdout:setvbuf('no')
 
</source>
 
</source>
  
== Jumping to errors ==
+
=== 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.
 
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 ==
 
== See also ==
* [http://www.sublimetext.com/2 Sublime Text 2 Website]
+
* [https://www.sublimetext.com/ Sublime Text Website]
* [http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/build_systems.html Sublime Text 2 Build Systems]
+
* [https://stackoverflow.com/questions/16338523/live-console-output-in-sublime-text-2 Stack Overflow question about console output]
* [http://stackoverflow.com/questions/16338523/live-console-output-in-sublime-text-2 Stack Overflow question about console output in Sublime Text 2]
 
  
 
[[Category:Software]]
 
[[Category:Software]]
[[Category: Editor integration]]
+
[[Category:Editor integration]]
  
{{#set:Name=Sublime Text 2}}
+
{{#set:Name=Sublime Text}}
 +
{{#set:Author=Jon Skinner, Sublime HQ}}
 +
{{#set:License=Shareware}}
 +
{{#set:Type=Editor}}
 +
{{#set:Status=Active maintenance}}
 
{{#set:Description=Source Code Editor}}
 
{{#set:Description=Source Code Editor}}
{{#set:Type=Editor}}
+
{{#set:Screenshot=File:lualove.png}}

Latest revision as of 07:44, 16 February 2024

Fast and customizable cross-platform code editor.

Sublime Text with Lua Love package on Linux

Lua Love package

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

Installation

  1. Install Package Control and restart Sublime Text
  2. Press Ctrl+Shift+P to open the Command palette and enter Package Control: Install Package
  3. Wait until another input field appears and install the Lua Love package
  4. In the Command palette enable syntax highlighting with Set Syntax: LOVE
  5. Now select build system with Ctrl+Shift+B to LuaLove and then you can use Ctrl+B to start LOVE.
  6. Optional: Set LOVE syntax as default for all .lua files - ViewSyntaxOpen all with current extension as...LOVE
  7. Optional: If LOVE is not in your PATH variable, go to PreferencesPackage SettingsLua Love and add:
{
    "build_system.love.cmd": ["absolute/path/to/love/executable", "${project_path:${folder:${file_path}}}"]
}

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