Sublime Text Plugin Quickstart

Based on the fact that the Sublime Text plugin example page is outdated below is a quick guide to create a Sublime Text Plugin for Sublime Text 2

  1. Go to Tools > New Plugin to auto generate a template for a plug-in
    import sublime, sublime_plugin
    
    class ExampleCommand(sublime_plugin.TextCommand):
        def run(self, edit):
            self.view.insert(edit, 0, "Hello, World!")
  2. Save it as a .py file in Packages/User folder (it should be the default folder when you select save). I chose testPlugin.py
  3. You can run in from the Sublime Text console (Ctrl + ~ in Windows) using the following command. (if it doesn’t work try, try saving the file again with the console open to see any errors and also try closing and reopening Sublime Text)
    view.run_command("example")

Running Camel Case Commands

Use underscores

class ExampleTextCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.insert(edit, 0, "Hello, World!")
 view.run_command("example_text")

sublime.Edit & sublime_plugin.EventListener

If an edit object is needed (seems to be needed for writing things on the page), use view.begin_edit() but don’t forget to end_edit()

They can be created by view.begin_edit(). Every call to view.begin_edit() must have a corresponding call to view.end_edit(), typically wrapped in a try … finally block.

Sublime Text 2 API reference

The EventListener class let’s you trigger things on an event happening and the code below shows inserting text to a document when it is opened. (Disclaimer: I’m not fluent in Python so I’m not sure if the below is fully correct but it does seem to work)

import sublime, sublime_plugin
class OnOpenCommand( sublime_plugin.EventListener):
   def on_load(self, view):
       try :
           edit = view.begin_edit()
           view.insert(edit, 0, "on load")
       finally :
           view.end_edit(edit)
Advertisement

iPad screenshot crashes iPad 2 (iOS 5.1)

Somehow I managed to crash my iPad 2 by trying to edit an image in the Photos app. This is a repeatable problem and I’ve tried restarting, closing all apps and it still happens. Check out the video below to see the problem in action

The offending image is below: try saving it on your iPad and try editing it in the Photos app to see if this happens on your iPad.  In current testing, it doesn’t seem to affect the new iPad (3rd gen), iPhone 4 or iPod Touch (4th gen).  I can still edit other photos or screenshots so this totally puzzles me and is completely reproducible. It this another one of those special Apple bugs just for me?

iPad 2 launch in Brunei

After hearing word of the iPad 2 launch in Singapore on the 29th while doing Tech Talk Coffee Shop tonight, I was surprised to see that AV Electronics, the premium Apple reseller in Brunei is also having their launch on Friday 29th at 10am at both their Kiulap and Mall stores. Singapore prices are listed below and I would think Brunei prices will be slightly higher, perhaps B$50 to B$150 higher, but kudos to AV Electronics for getting it the same day as Singapore. From the Facebook page AVE mentioned that they have “around 100 different SKU of accessories” but the iPad 2 dock won’t make it in time for the launch.

Singapore iPad 2 Pricing

WiFi

  • 16GB: SGD$668
  • 32GB: SGD$798
  • 64GB: SGD$928

WiFi + 3G

  • 16GB: SGD$848
  • 32GB: SGD$978
  • 64GB: SGD$1,108