Working with Sublime

share on google plus share on facebook share on twitter share on linkedin share via email

Sublime Text is great, but using it properly is not as transparent as what most of us are used to. I will try to list here some of the things i had to figure out to start working efficiently.

Below are a list of topics that will be addressed in this post. Most of the sections are still empty and are just “reminders to myself”. I will get to them as soon as possible…

General (under construction)

  • packages
  • projects
  • settings
  • templates

Python

The only package i have used so far for Python development is Anaconda (not to be confused with the homonymous Python distribution). It works nicely out of the box, but overwriting some of the default settings can be useful.

Open the user-defined package settings file:

Preferences > Package Settings > Anaconda > Settings - user

I have made the following changes to that file:

{

    "anaconda_linter_mark_style": "none",
    "anaconda_linter_underlines": false,
    "pep8_ignore":
    [
        "E221",
        "E203",
    ],
    "pep8_max_line_length": 120,
    "extra_paths":
    [
        "/Users/vanmelet/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/IronPython/settings/lib",
    ],

}

Line 3 and 4 turn off Anaconda’s linter. Lines 5 to 9 turn off some of the PEP 8 directives (E221: multiple spaces before operator, E203: whitespace before ‘:’). The full list of directives can be found here. Line 10 sets the allowed length for lines to 120. I have also added the path to the RhinoPython lib to get code completion for Rhino related Python functionality.

Some of the other settings have to be defined on a project-per-project basis. To open the project settings file:

Project > Edit Project

I have turned off the “auto_python_builder_enabled” setting and changed the default python interpreter. I have also added a few alternative build systems.

{
	"settings":
	{
		"auto_python_builder_enabled": false,
		"python_interpreter": "/opt/local/bin/python2.7"
	},

	"build_systems":
	[
		{
			"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
			"name": "MacPorts Python2",
			"selector": "source.python",
			"shell_cmd": "\"/opt/local/bin/python2.7\" -u \"$file\""
		},
		{
			"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
			"name": "MacPorts Python3",
			"selector": "source.python",
			"shell_cmd": "\"/opt/local/bin/python3.4\" -u \"$file\""
		},
		{
			"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
			"name": "Anaconda Python2",
			"selector": "source.python",
			"shell_cmd": "\"/anaconda/bin/python2.7\" -u \"$file\""
		}
	],

	"folders":
	[

	],
}

LaTeX

Packages i have used (a little bit) so far are LaTeXing and LaTeXTools. I prefer LaTeXTools because it is completely free. LaTeXing can be used freely as well, but, as far as i know, you have to buy a license to get rid of the annoying popup at every build. Both can be installed using package control (on mac: shift+cmd+P > type “install” > select “Package Control: Install Package”).

First create a new latex project, add a main *.tex file, and see if it runs:

  1. Create a folder somewhere.
  2. Open a new Sublime window.
  3. Add the folder to the project.
  4. Create a file in the project folder: document.tex (the name is not important…).
  5. Add an article snippet to the file: cmd+L,S (hold down command and press first L and then S) > select “Snippet: New article”
  6. Build the file: cmd+B

Make sure the build system is set to LaTeX before you build (you only have to do this once):

Tools > Build System > LaTeX

If the build is succesful, great! If it is not, the plugin probably can’t find your LaTeX executables. To let LaTeXTools know where the executables are you have to modify the settings file:

Preferences > Package Settings > LaTeXTools > Settings - user

In the section about “Platform settings” update the “texpath” of your platform (I am on OSX):

{

// ------------------------------------------------------------------
// Platform settings: adapt as needed for your machine
// ------------------------------------------------------------------

    "osx": {
        "texpath" : "$PATH:/Library/TeX/texbin:/usr/texbin:/usr/local/bin:/opt/local/bin:/usr/local/texlive/2012/bin/x86_64-darwin"
    }

}

If you don’t know which path to add and you are using something like TeXlipse, check the builder settings in Eclipse… After this, the build should work. If you have installed the recommended viewer for your platform (on mac this is Skim), the generated pdf will open automatically. It may be behind the Sublime window…

You will notice that a bunch of files were generated by the build cluttering your project folder. If you don’t like this, you can specify a different directory in which these files should be created by updating the project settings:

Project > Edit Project
{

    "folders":
    [
        {
            "path": "/path/to/your/project/folder"
        }
    ],
    
    "settings":
    {
        "output_directory": "/path/to/your/project/folder/tmp"
    }

}

Version control (under construction)

For version control i still use Eclipse or SourceTree…

Leave a response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>