Artificial Intelligence, Programming, GPU Programming and Electronics

Download

First

What is Sublime Text 2 and what does the Perforce Plugin do?

Sublime Text 2 is a light weight text editor that is really fast and extendable. At the moment, I use it to edit PHP, Python, HTML, CSS and JavaScript files. There is a lot of community support to provide plugins (programmed in Python) so the editor keeps improving.

Trying to do my part, I did a small Perforce integration plugin. Right now it takes for granted that you have an open ticket with your Perforce server, otherwise the actions will simply fail. The plugin is still work in progress but I try to work on it daily to add features here and there.

Getting Started

Getting Sublime Text 2

At the time of writing, Sublime Text 2 is “free” (a pop up will appear every now and then to suggest you buy a license) or available for pretty cheap, 59$. For such a great editor, I highly recommend buying it to support the developer. Download

Getting Perforce Plugin

My plugin is available in a couple of ways, but here’s my recommendations:

  • Download and install Package Control for Sublime Text 2
  • Open the command window (ctrl+shift+p in the default install)
  • Select Package Control: Install Package
  • Type “perforce”, press enter

or

  • Browse to GitHub for my Sublime Text 2 Perforce Plugin repository
  • Download the Zip File
  • Locate your “roaming app data” folder, on Vista (old laptop, I know…) it’s located here: C:\Users\*your username*\AppData\Roaming
  • Browse to Sublime Text 2\Packages
  • Create a Perforce folder
  • Copy the content of the folder ericmartel-Sublime-Text-2-Perforce-Plugin-?????? in the newly created Perforce folder so that Perforce.py resides in the root of Sublime Text2\Packages\Perforce

Features

Event Handling

The plugin has two commands that react to events related to saving files.

Auto Add

When the plugin detects that you’re trying to save a new file (didn’t exist pre-save, exists post-save) and the file resides within your client root, it will automatically mark it for add.

You can disable this feature by changing the value of perforce_auto_add to false.

Auto Checkout

When the plugin detects that you’re modifying (perforce_auto_checkout_on_modified set to true) or you’re trying to save an existing file (exists pre-save – perforce_auto_checkout_on_save set to true) and the file resides within your client root, it will automatically try to checkout the file. For the moment there’s no handling of exclusive checkout or other conditions that could make the checkout fail.

You can disable this feature by changing the value of perforce_auto_checkout to false.

Text Commands

The text commands are all available through the command window (ctrl+shift+p in the default install). By typing perforce you can filter only the commands related to this plugin:

Filtered Perforce Text Commands

As you can see, you will even see the keyboard shortcuts assigned to these commands, as an example I assigned “ctrl+alt+x” to the Graphical Diff with Depot. Triggering the command from this window, from the Console (ctrl+`), from a menu item or from a keyboard shortcut will all result to the same thing.

These commands all redirect the p4 output to the Console window (ctrl+`) and a warning in some cases where the file in the view is not in the client root, if the perforce_warnings_enabled setting is set to true.

perforce_checkout

This command will attempt to checkout the file in the current view. Not much error handling is made. Use this command to manually control your checkout, if the perforce_auto_checkout setting is set to false.

perforce_add

This command will attempt to add the file in the current view. This is useful if the file was not created directly through Sublime Text 2 or if the perforce_auto_add setting is set to false.

perforce_rename

This command will prompt you for a new name for the file in the current view.

perforce_delete

This command will delete the file in the current view from Perforce.

perforce_revert

This command will attempt to revert the changes made to the file in the current view.

perforce_diff

This command outputs directly the result of a call to p4 diff with the file in view to the Console (ctrl+`). Recommended to more advanced users as the output is not really user-friendly.

perforce_graphical_diff_with_depot

This command calls p4diff and compares the local version of the current file with the version in the depot. I wish I could extend this to support Araxis Merge, but unfortunately I’m on sick leave for a couple of months and don’t feel like buying a license for my personal needs. Feel free to donate one and I’ll make the plugin configurable ;)

perforce_create_changelist

This command will create an empty changelist and prompt the user for a single line description.

perforce_add_line_to_changelist_description

This command lists all the available changelists and then lets the user type a line to be added to the description.

perforce_move_current_file_to_changelist

This command lists all the available changelists, adding “New” to the list. By selecting a changelist, the file will be moved to this changelist. If new is selected, the user is prompted to enter a description for the new changelist.

perforce_list_checked_out_files

This command lists all the files that are currently checked out sorted by changelist with part of the changelist description.

List of Checkedout Files

Here’s my current listing for a small web project I’m working on. Under the black square is the rest of the local path, but I didn’t want to make public the name of my project yet!

Menus

All the commands are easily available through the Tools menu (screenshot not updated):

What’s Next?

Please make suggestions. The plugin does what I need for now, I might polish it or update it depending on my usage but if you’d like something added, feel free to ask!

How you can contribute

I will gladly accept bug reports on GitHub and suggestions by email (or use the contact form on this page if you can’t find my email address – with all the spam I keep receiving recently it shouldn’t be hard to find).

I keep a changelog in the main file of this plugin so you will be credited for your contribution!

Also, please buy Sublime Text 2 to support its developer!