Giter Site home page Giter Site logo

subl's Introduction

subl:// URL handler

A subl:// URL handler for Sublime Text 2 and Sublime Text 3 on Mac OSX. Made very quickly in AppleScript. If you're a Windows user, try this Windows Sublime Text subl:// URL handler.

Follows the syntax of the TextMate URL scheme.

Gloms onto the following URL schemes:

  • subl://
  • sublime://
  • txmt:// (compatibility with existing PHP debug tools)

Installation

  • Download and unzip Subl.app.zip
  • Move Subl.app to your /Applications directory
  • Open once to register the handler

How to use

Generate URLs in the following format: subl://open?url=file://{{file}}&line={{line}}&column={{column}}

Examples:

  • subl://open?url=file:///path/to/file.php&line=12&column=4
  • subl://open?url=file:///path/to/other.php&line=192

Args

  • url - Absolute file:// link to the file, e.g. file:///path/to/file.txt
  • line - Line number in the file, e.g. 192
  • column - Column number in the file, e.g. 14

url is the only required argument. All others are optional. If you don’t specify a url, Subl.app will throw an error dialog.

Path

Subl looks for your Sublime Text app in three locations in the following order:

  1. /Applications/Sublime Text 3.app
  2. /Applications/Sublime Text 2.app
  3. /Applications/Sublime Text.app

As a quick fix, if your Sublime Text app isn't in any of these locations, you can just rename and move it so it does match one of them.

Sublime Text and PHP errors

This code snippet will re-route all PHP errors to a custom error handler, and turn filenames into clicky Sublime Text links.

// Custom error handler function.
// Turns filenames into clicky subl:// links (requires http://github.com/dhoulb/subl)
// Also cleanses the ugly part of pathnames, so "/long/path/to/file/name.php on line 7" becomes "name.php - 7"
function subl_handler($level, $error, $file, $line)
{
	// Check if error reporting is off.
	if ($level === 0) return;

	// Is there a file?
	if ($file)
	{
		// Ugly part to strip off the path name.
		$strip = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR;

		// Change $file to a clicky link.
		$file = '<strong><a href="subl://open?url=file://' . $file . '&line=' . $line . '">'
		. str_replace($strip, '', $file)
		. ' - ' . $line
		. '</a></strong>';
	}

	// Output the file and the error.
	echo '<pre class="error">';
	if ($file) echo $file . '<br>';
	echo $error;
	echo '</pre>';
}

// Additional function to enable handling for fatal errors too.
function subl_shutdown() { if ($error = error_get_last()) subl_handler($error['type'], $error['message'], $error['file'], $error['line']); }

// Register handlers.
set_error_handler('subl_handler', E_ALL); // Register custom function as the error handler.
register_shutdown_function('subl_shutdown'); // Register the custom shutdown function.
ini_set('display_errors', false); // Turn off built-in errors.

Remember: It's recommended to show no errors at all on live production websites. PHP errors leak details than can be useful to attackers.

Sublime Text and Ruby on Rails errors

Install Subl.app as above, and include Better Errors in your Rails application.

Use the following code snippet to tell Better Errors to use Subl.app as its editor. Change local_path to the full base path of your application.

if defined? BetterErrors
  BetterErrors.editor = proc { |full_path, line|
    full_path = full_path.sub(Rails.root.to_s, local_path)
    "subl://open?url=file://#{full_path}&line=#{line}"
  }
end

See the Better Errors Wiki for more information about pointing editor links at Sublime Text.

General comments

Hopefully some day a URL scheme will be baked in to Sublime Text, and all of this will be unneccessary!

See this thread on the Sublime Text support system, and upvote if you think this is important.

subl's People

Contributors

dhoulb avatar pascaliske avatar wacko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.